Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-05-07 : 11:03:56
|
| George writes "How do you write the most efficient SQL statement to query one parent table with more than two tables? For example:User - Main tableUser_Line_Item - Parent Table Line_Item_Monitor - Child Table Line_Item_Computer- Child Table Line_Item_Printer - Child TableIf you want to get the following information:- User - First_Name- User_Line_Item - Purchase_Date- Line_Item_Monitor - Resolution- Line_Item_Computer - Processor- Line_Item_Printer - CartridgeHow can you write the most effective SQL statement to display the above information in one line (one record - First_Name, Purchase_Date, Resolution, Processor, Cartridge)? Do you use UNION or create VIEW and How? Please give an SQL statement example." |
|
|
DavidD
Yak Posting Veteran
73 Posts |
Posted - 2002-05-07 : 20:59:01
|
| select a.first_name, b.Purchase_Date, c.Resolution, d.Processor, e.Cartridgefrom user a join User_Line_Item b on a.linkfield = b.linkfield join Line_Item_Monitor c on b.linkfield = c.linkfield join Line_Item_Computer d on b.linkfield = d.linkfield join Line_Item_Printer e on b.linkfield = e.linkfieldThis is a basic SQL Query, you can use it to create a view if you wish, but it depends what purpose the query is for if that is necessary (ie who is accessing the resultset? How? Security considerations etc). A union query would not be used for this scenario.RegardsDD |
 |
|
|
|
|
|