Presentation is loading. Please wait.

Presentation is loading. Please wait.

Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is.

Similar presentations


Presentation on theme: "Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is."— Presentation transcript:

1 Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is officially called View in SQL. QUERY in Access can be SELECT, INSERT, UPDATE, or DELETE. You can create a query against a table or a query. You can create a form or report against a table or a query.

2 Access - 2 Date Literal Format Oracle SQL: SELECT D_O_H, F_NAME, L_NAME FROM INSTRUCTOR WHERE D_O_H < '01-JAN-90' ORDER BY D_O_H; Access SQL: SELECT D_O_H, F_NAME, L_NAME FROM INSTRUCTOR WHERE D_O_H < #01/01/1990# ORDER BY D_O_H;

3 Access - 3 String Wild Card Search Oracle SQL: SELECT NAME, CITY FROM STUDENT WHERE CITY LIKE 'FAIR%'; Access SQL: SELECT NAME, CITY FROM STUDENT WHERE CITY LIKE 'FAIR*';

4 Access - 4 String Wild Card Search Oracle SQL: SELECT NAME, CITY FROM STUDENT WHERE CITY LIKE 'FAIR_ _ _'; Access SQL: SELECT NAME, CITY FROM STUDENT WHERE CITY LIKE 'FAIR??? ';

5 Access - 5 Sort By Clause Oracle SQL: SELECT L_NAME, F_NAME, SALARY * 0.1 AS BONUS FROM INSTRUCTOR ORDER BY BONUS DESC, L_NAME; Access SQL: (cannot use alias column name in Order By clause) SELECT L_NAME, F_NAME, SALARY * 0.1 AS BONUS FROM INSTRUCTOR ORDER BY 3 DESC, L_NAME;

6 Access - 6 String Concatenation Oracle SQL: SELECT L_NAME | | ', ' | | F_NAME | | ' ' | | M AS NAME FROM INSTRUCTOR; Access SQL: (use & instead of || for string concatenation) SELECT L_NAME & ', ' & F_NAME & ' ' & M AS NAME FROM INSTRUCTOR;

7 Access - 7 Substring Function Oracle SQL: SELECT SUBSTR(DIV_NAME,1,4) "SUBS" FROM DIVISION; Access SQL: (use LEFT string function) SELECT Left(DIV_NAME,4) as SUBS FROM DIVISION;

8 Access - 8 Trunc() vs Round() Oracle SQL: SELECT DIV, TRUNC(AVG(SALARY)/52, 2) AS AVG_SAL FROM INSTRUCTOR GROUP BY DIV HAVING COUNT(*) > 1 ORDER BY DIV; Access SQL: (use & instead of || for string concatenation) SELECT DIV, Round(AVG(SALARY)/52,2) as AverageSalary FROM INSTRUCTOR GROUP BY DIV HAVING COUNT(*) > 1 ORDER BY DIV;

9 Access - 9 Date Function Oracle SQL: SELECT I_NO, TRUNC(MONTHS_BETWEEN(SYSDATE, D_O_B)/12, 0) AS AGE FROM INSTRUCTOR; Access SQL: (Date function) SELECT I_NO, ROUND(DateDiff("m", D_O_B, Now)/12, 0) AS AGE FROM INSTRUCTOR;

10 Access - 10 Insert Statement Oracle SQL: INSERT INTO INSTRUCTOR (I_NO, L_NAME, M, F_NAME, SALARY) VALUES (60, 'SMITH', 'F', 'BOB', 60000); Access SQL: (The Insert statement above will work in Access; however, when you switch to design mode, the Insert statement will be changed to the following statement by Access automatically) INSERT INTO INSTRUCTOR ( I_NO, L_NAME, M, F_NAME, SALARY ) SELECT 60 AS Expr1, 'SMITH' AS Expr2, 'F' AS Expr3, 'BOB' AS Expr4, 60000 AS Expr5;

11 Access - 11 Count and Distinct Statement Limitation Oracle SQL: SELECT COUNT(DISTINCT CITY) FROM STUDENT; -- Answer: 3 (excluded NULL value records from the count) Access SQL (Include NULL value; cannot use distinct and Count together) You have to use the SQL view to enter the distinct keyword. It will not work in the Design view. SELECT DISTINCT (CITY) FROM STUDENT;

12 Access - 12 How to count distinct values 1 2 3 4 5 6 Create the first query using distinct and save it as DistinctTitles Create the second query against the DistinctTitles query. Use count function in this second query.

13 Access - 13 SQL Join Oracle: (This works in Access as well) SELECT TITLE, COURSE.C_ID, LOCATION, START_DATE FROM COURSE, OFFERING WHERE COURSE.C_ID = OFFERING.C_ID ORDER BY TITLE; Access SQL and SQL-92 Standard: (May not work in Oracle SQL*Plus) SELECT Title, COURSE.C_ID, LOCATION, START_DATE FROM COURSE INNER JOIN OFFERING ON COURSE.C_ID = OFFERING.C_ID ORDER BY TITLE;


Download ppt "Access - 1 Table Query (View) FormReport Database Application Basic Database Objects Relationships among Access Database Objects A saved SELECT query is."

Similar presentations


Ads by Google