Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Return Multiple lines from joined table

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
Morpheus7
Asked:
Morpheus7
2 Solutions
 
Steve WalesSenior Database AdministratorCommented:
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
 
jleenotloCommented:
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
 
Morpheus7Author Commented:
Many thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now