Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Return Multiple lines from joined table

Posted on 2013-12-12
3
Medium Priority
?
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Steve Wales earned 1000 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 1000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

722 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