Presentation is loading. Please wait.

Presentation is loading. Please wait.

NTAUG Introduction in to use of SQL - Part 2 Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,

Similar presentations


Presentation on theme: "NTAUG Introduction in to use of SQL - Part 2 Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,"— Presentation transcript:

1 NTAUG Introduction in to use of SQL - Part 2 Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,

2 SQL Review Review

3 SQL SQL Some Basic SQL Rules Multiple SQL statements are separated by semicolons (;) SQL statement keywords are not case sensitive SQL statement data values are case sensitive All extra white spaces within a SQL statement are ignored. You can add spaces and carriage returns for readability. SQL statements are made up of clauses (e.g., SELECT clause, FROM clause, WHERE clause, etc.)

4 Common Conventions Used This is the commonly used notation styles and conventions: SELECT [DISTINCT] {* | column-list} FROM table-name Uppercase words = keywords Lowercase words = user supplied data value { } = required items [ ] = optional items | = various choices … = repeating set

5 SELECT Statement A full SELECT statement consists of 6 clauses: SELECT FROM WHERE GROUP BY HAVING ORDER BY A regular query consists of: SELECT FROM WHERE ORDER BY A grouping (summary) query consists of: SELECT FROM GROUP BY HAVING ORDER BY

6 Syntactical Diagram of the SELECT Statement ORDER BY ALL * HAVING GROUP BY SELECT FROM WHERE SEARCH CONDITION DISTINCT SELECT-LIST SPECIFY COLUMNS SEARCH CONDITIONS SPECIFY GROUP SORT SPECIFY COLUMN SORT Not all clauses must be used in a query. The minimum that you need for a SELECT statement is SELECT and FROM.

7 SQL WHERE clause We touched earlier on the where clause We touched earlier on the where clause SELECT job_name FROM job WHERE machine=somename SELECT job_name FROM job WHERE machine=somename And made the use of the simplest form and equals = There are other operators: =Equal <>Not equal >Greater than <Less than >=Greater than or equal <=Less than or equal BETWEEN Between an inclusive range LIKESearch for a pattern

8 SQL WHERE clause To extract information where you have a list of items: To extract information where you have a list of items: SELECT job_name FROM job WHERE machine IN (machine1,machinezxt,machine1b) SELECT job_name FROM job WHERE machine IN (machine1,machinezxt,machine1b)

9 SQL Select within Select SELECT job_name FROM job WHERE machine IN (SELECT hostname FROM keymaster) SELECT job_name FROM job WHERE machine IN (SELECT hostname FROM keymaster)

10 SQL Information from multiple tables Examine the following statement: Examine the following statement: SELECT keymaster.hostid, job.job_name FROM keymaster, job WHERE job.machine=keymaster.hostname SELECT keymaster.hostid, job.job_name FROM keymaster, job WHERE job.machine=keymaster.hostname

11 Constructing more WHEREs using NOT

12 Select WHERE & ORDER xql>>[AUTOSYS_SQL_DEV1][autosys] 1> select job_name,owner from job where job_name like 'test%' order by joid ; xql>>[AUTOSYS_SQL_DEV1][autosys] 1> select job_name,owner from job where job_name like 'test%' order by joid ; job_nameowner ----------------------------------------------------- test_bdsaptc1 autosys test_bdsdbc1 autosys test_bdsaptc1 autosys test_bdsdbc1 autosys

13 SQL Introduction As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database. As stated earlier, this was introduction to SQL and hopefully has provided a taste of the things that can be done to extract information directly from the AutoSys database. pdominey@dominey.biz pdominey@dominey.biz pdominey@dominey.biz www.dominey.biz www.dominey.biz www.dominey.biz


Download ppt "NTAUG Introduction in to use of SQL - Part 2 Peter Dominey Copyright © Peter Dominey 2004, Copyright © Peter Dominey 2004,"

Similar presentations


Ads by Google