Solved

Return Multiple lines from joined table

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

746 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