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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble w/Query

Status
Not open for further replies.

jl39775

Programmer
Feb 19, 2004
5
0
0
US
I have two tables with a 1 to many relationship.
For example

table1 (parent)
id(key)
col1
col2

table2 (child)
id (foreign key)
col1

Is there a select statement that I can use to combine data from both table with the same key into one record when table2 has many related records to table1.

Example
table1.id table1.col1 table1.col2 (1st record from table1)table2.col1 (2nd record from table1)table2.col1 (3rd record from table1)table2.col1

Instead of
row 1
table1.id table1.col1 table1.col2 (1st record from table1)

row 2
table1.id table1.col1 table1.col2 (2nd record from table1)table2.col1

row 3
table1.id table1.col1 table1.col2 (3rd record from table1)table2.col1

Please help,

James
 
There is no way to do it efficiently. This type of query is a bad idea.



Questions about posting. See faq183-874
 
It might be worth exploring the SQL Enterprise Manager's query builder. That way you can play around a bit and see if you can get something similar to whay you need.

If you open SQL Enterprise manager, then go to Your database, then tables, then select a table, right click and select query - then you can add / remove tables and visually build a query and get the results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top