Solved

Return Multiple lines from joined table

Posted on 2013-12-12
3
290 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 and will be exposed to the many uses the SELECT statement has.

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now