access - 1 table query (view) formreport database application basic database objects relationships...
Post on 20-Dec-2015
216 views
TRANSCRIPT
Access - 1
Table
Query(View)
Form ReportDatabaseApplication
Basic DatabaseObjects
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.
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;
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*';
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??? ';
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;
Access - 6
String Concatenation
Oracle SQL:
SELECT L_NAME | | ', ' | | F_NAME | | ' ' | | M AS NAMEFROM INSTRUCTOR;
Access SQL: (use & instead of || for string concatenation)
SELECT L_NAME & ', ' & F_NAME & ' ' & M AS NAMEFROM INSTRUCTOR;
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;
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;
Access - 9
Date FunctionOracle SQL: SELECT I_NO,
TRUNC(MONTHS_BETWEEN(SYSDATE, D_O_B)/12, 0) AS AGEFROM INSTRUCTOR;
Access SQL: (Date function)SELECT I_NO,
ROUND(DateDiff("m", D_O_B, Now)/12, 0) AS AGEFROM INSTRUCTOR;
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;
Access - 11
Count and Distinct Statement LimitationOracle 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;
Access - 12
How to count distinct values1
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.
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_DATEFROM COURSE INNER JOIN OFFERING ON COURSE.C_ID = OFFERING.C_IDORDER BY TITLE;