Download presentation
Presentation is loading. Please wait.
Published byLee Spencer Modified over 8 years ago
1
Query Lab CSC 240 Blum1
2
Log on to PMA (PHPMyAdmin) and click on the Northwind database CSC 240 Blum2
3
Alternative place to work: http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all CSC 240 Blum3
4
After choosing the Northwind database, click on the Query tab CSC 240 Blum4
5
Use the drop-down to choose `customers`.* Then check the Show checkbox. Then click The Update Query button CSC 240 Blum5 The marks around the table name seen here are called tick marks or back-ticks. They slant and are above the Tab on the upper left of the keyboard. They are NOT single quotes. They are not necessary in this case but PMA includes them.
6
Key words SELECT – In SQL a SELECT statement is one that looks at a subset of data – As opposed to adding data (INSERT), taking away data (DELETE) and changing data (UPDATE) FROM – FROM indicates the source of the data – which tables that data comes from CSC 240 Blum6
7
Next click the Submit Query button CSC 240 Blum7
8
Result: 94 records (displaying 30 per page) CSC 240 Blum8
9
Click on Northwind to move from the specific customers table to the more general Northwind database CSC 240 Blum9
10
Click on the Query tab. This time select specific fields (instead of * for all fields). Remember to check Show and click Update Query. CSC 240 Blum10
11
Result from clicking the Submit Query button. It produces the same number of records but fewer fields per record. CSC 240 Blum11
12
Projection In “relational algebra” the previous query is an example of a projection – we have projected out some of the fields. (Don’t be intimidated by the term “relational algebra” it just means things we can do to database tables.) CSC 240 Blum12
13
YOU DO #1 Make a Word document and paste into the SQL for – The first name and last name of Employees CSC 240 Blum13
14
Return to Northwind/Query. Choose `customers`.* and Show for one column and `customers`.`City` and ='London' as the Criteria CSC 240 Blum14
15
Click Update to show the query CSC 240 Blum15
16
WHERE – selection The new keyword appearing is WHERE – It is used to limit the record that will display to those that meet some condition In relational algebra, this procedure of limiting the number of records is known as selection Note in this case that the WHERE condition uses single quotes – different from ticks CSC 240 Blum16
17
Result of selecting customers whose city is London. 4 records. CSC 240 Blum17
18
Compound condition: City is London or Berlin CSC 240 Blum18
19
Results of Compound condition: City is London or Berlin CSC 240 Blum19
20
YOU DO #2 Paste into your Word document the SQL for – Suppliers whose Country is France or Germany CSC 240 Blum20
21
Compound condition: contactTitle is Owner and Country is Mexico CSC 240 Blum21
22
Result of Compound condition: contactTitle is Owner and Country is Mexico CSC 240 Blum22
23
YOU DO #3 Paste into your Word document the SQL for – Employees whose Title is sales Representative and Country is USA CSC 240 Blum23
24
Combining selection and projection CSC 240 Blum24 selection projection
25
Result of selection and projection CSC 240 Blum25
26
Sort result by choosing Ascending or descending from the drop-down under a field. CSC 240 Blum26
27
Keywords for sorting ORDER BY – Is followed by the field (or fields) upon which the sorting will be based ASC – Indicates the results will be shown from lowest to highest numerically or in alphabetic order for text/strings DESC – Highest to lowest or reverse alphabetical CSC 240 Blum27
28
Results of query sorted on CompanyName CSC 240 Blum28
29
YOU DO #4 Paste into your Word document the SQL for – Products sorted by ProductName CSC 240 Blum29
30
Obtaining a list of customer countries CSC 240 Blum30
31
Result of customer country query (so far). Click on Edit to work on further. CSC 240 Blum31
32
SQL editing dialog box arises CSC 240 Blum32
33
Add keyword DISTINCT to eliminate duplicate country results CSC 240 Blum33
34
Click Go. Query updated. And only unique countries occur in result CSC 240 Blum34
35
YOU DO #5 Paste into your Word document the SQL for – Distinct cities of employees CSC 240 Blum35
36
Criteria other than equality: Products with a UnitPrice less than 20 CSC 240 Blum36
37
Result of Products with a UnitPrice less than 20 CSC 240 Blum37
38
Products with a UnitPrice greater than or equal to 30 CSC 240 Blum38
39
Result of Products with a UnitPrice greater than or equal to 30 CSC 240 Blum39
40
Switching >= to > CSC 240 Blum40
41
A BETWEEN query criteria: UnitPrice between 20 and 30 CSC 240 Blum41
42
Results of BETWEEN query: UnitPrice between 20 and 30 CSC 240 Blum42
43
YOU DO #6 Paste into your Word document the SQL for – Products having a UnitsInStock less than or equal to 15 CSC 240 Blum43
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.