Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select from Multiple tables.

Status
Not open for further replies.

PSFMIS

MIS
Feb 3, 2006
28
US
Could someone give me an example on how to do this.

I have 2 or more tables that have a ID field that will be the same in each table. I need to create a sql Select and combine into one recordset some fields from all the tables. The first table will always contain all records that may be in the 2nd 3rd ..etc table. I've tried differnt ways of using join and union but I can't figure this out.

Please help
 
try something like this...
Code:
SELECT T1.field1, T1.field2 FROM Table1 T1
Left Outer Join Table2 T2 ON
T1.ID=T2.ID

it would be better if you post some sample data from your tables and the kind of output you are looking for...then we can come up with the exact query that you are looking for...

-DNG
 
I ended up doing this.. I'm trying to make a few small databases that all contain different fields that use the same ID and link them together into one large recordset for my asp page.

Code:
strSQL_LogData ="SELECT field1, field2, field3 " + _ 
		"FROM Table1 " + _
		"LEFT JOIN Table2 " + _
		"ON Table2.ID = Table1.ID " + _
		"LEFT JOIN Table3 " + _
		"ON Table3.ID = Table2.ID"

When joining these tables could I run into any field number or table number restrictions or anthing? I'm using .dbf database files created in Visual Foxpro.

I could also use some good links for getting started setting up Microsoft SQL server express also...

Thanks,
Aaron
 
For string concatination, it is best to use the ampersand "&" instead of the plus "+"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top