课程: SQL Practice: Basic Queries

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Retrieve data from multiple tables

Solution: Retrieve data from multiple tables - SQL教程

课程: SQL Practice: Basic Queries

Solution: Retrieve data from multiple tables

- [Instructor] This code challenge is going to use two tables for my database, the Customers table and the Reservations table. The tables are linked on a foreign key, a one-to-many relationship where each customer can have one or more reservations. In the beginning code, I'm just selecting from the Reservations table, and when I click Test my code, I get back a whole lot of data, but not too much context. Now, I'm going to paste in my solution. First of all, I'm getting data from two different tables, the Reservations and the Customers table, and I'm using an INNER JOIN, meaning I'm connecting the two parts of the foreign key together, and I'm connecting on the CustomerID columns of each of the two tables. I'm sorting the return to data by the Date in descending order, so I'll see the newest reservation first. And I'm only going to retrieve two reservations. That's done with the TOP 2 clause in the SELECT statement.…

内容