1 / 12

Database Design and Development

Database Design and Development. SQL – SELECT (MULTIPLE). Learning Intention. I will learn how to use SQL to SELECT data from multiple tables. SELECT (multiple tables). So far you have only selected fields from one table in an SQL statement. Need to be able to select fields from two tables.

egriffis
Download Presentation

Database Design and Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Design and Development SQL – SELECT (MULTIPLE)

  2. Learning Intention • I will learn how to use SQL to SELECT data from multiple tables.

  3. SELECT (multiple tables) • So far you have only selected fields from one table in an SQL statement. • Need to be able to select fields from two tables.

  4. SELECT (multiple tables) • To select fields from two tables you must include both tables in the FROM clause. e.g. FROM Resort, Hotel

  5. SELECT (multiple tables) • Also need to modify the WHERE clause to link the two tables using the Primary Key and it’s corresponding Foreign Key • This is called an EQUI-JOIN

  6. SELECT (multiple tables) SELECT field1, field2, field3, etc FROM table1, table2 WHERE table1.fieldPK = table2.fieldFK ORDER BY field2 ASC, field4 DESC;

  7. e.g. SELECT hotelName, town FROM Resort, Hotel WHERE Resort.resortID = Hotel.resortID;

  8. SELECT (multiple tables) • If you also need to find specific records then you add an AND after the WHERE. e.g. SELECT hotelName, town FROM Resort, Hotel WHERE Resort.resortID = Hotel.resortID AND starRating >= 4 ORDER BY hotelName ASC;

  9. SELECT (multiple tables) • If you need to find records where you are looking for results from two specific values in the same column then use OR and brackets. • If you need to view the value of the field which is used to join the tables then you need to put the table name in the SELECT too.

  10. SELECT (multiple tables) • e.g. SELECT Resort.resortID, town, hotelName FROM Resort, Hotel WHERE Resort.resortID = Hotel.resortID AND (town = "Ayr" OR town = " Glasgow");

  11. Pupil Task Complete the following: SQL Booklet Tasks 4, 5 and Extension Task 1

  12. Success Criteria • I can create SQL SELECT statements to select data from multiple tables.

More Related