Selecting fields from joined tables
I am new to SQL. I am trying to select some of the fields from 2 of 3 joined tables and all of the fields from a 3rd table. Other than specifying each individual field from the Pr table, is the a simpler way to SELECT individual fields from two of the tables and SELECT * from the 3rd table. My current query is below. This is an exercise from a book. If the 3rd table contained more fields this method would become very cum开发者_如何转开发bersome.
SELECT Lo.City ,
Em.FirstName ,
Em.LastName ,
Pr.EmpID ,
Pr.YearlySalary ,
Pr.MonthlySalary ,
Pr.HourlyRate
FROM Location AS Lo
INNER JOIN Employee AS Em ON Lo.LocationID = Em.LocationID
INNER JOIN PayRates AS Pr ON Em.EmpID = Pr.EmpID
Yes, you can use Pr.* to select all columns from the table aliased Pr.
This is widely discouraged in production code however as if the table definition changes your query can suddenly start bringing back loads of irrelevant data that is not needed.
加载中,请稍侯......
精彩评论