Solved

Return Multiple lines from joined table

Posted on 2013-12-12
3
299 Views
Last Modified: 2013-12-12
Hi,
I have 2 tables, table a and table b, I would like to be able to return 1 row from table a and multiple corresponding rows from  table b. How would I do this

Many thanks
0
Comment
Question by:Morpheus7
3 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 250 total points
ID: 39713991
As long as you have a column to match them on, it's as simple as

select a.col1, b,col2, ...
from tablea a
join tableb b on a.col1 = b.col2

So let's say you have a Purchase Order table where there's a PO Header and a PO Item table with multiple line items:

select a.po_no, b.po_item, b.qty, b.item_price
from po_hdr a
join po_item b
on a.po_no = b.po_no
0
 
LVL 1

Assisted Solution

by:jleenotlo
jleenotlo earned 250 total points
ID: 39714003
Try the following:
select a.*, b.* from a left join b on a.KeyID = b.KeyID

KeyID is the common identifier that creates the join between the 2 tables.
0
 

Author Closing Comment

by:Morpheus7
ID: 39714030
Many thanks
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question