0

I have 3 tables with values like below

**tbl_product**
recID      pID       price      colour
1         BDPLA-0001   1.23        White
2         BDPLA-0002   2.23        Black
3         BDPLA-0003   2.28        Blue

tbl_product_size
recID        pID       size       stock       
1            1         2.0cm       10 
2            1         3.0cm       20
3            2         2.5cm       30
4            3         3.6cm       40
5            3         3.8cm       50

tbl_order_details
recID       pID        quantity   size
201         BDPLA-0001   5        2.0cm 
202         BDPLA-0002   10       2.5cm

tbl_product = t
tbl_product_size = s
tbl_order_details = d

t.recID = s.pID
t.pID = d.pID

how can i combine the tables and produce result like this

t.pID       s.size       s.stock     d.quantity  t.price
BDPLA-0001  2.0cm        10          5           1.23
BDPLA-0001  3.0cm        20          null        1.23
BDPLA-0002  2.5cm        30          10          2.23
BDPLA-0003  3.6cm        40          null        2.28
BDPLA-0003  3.8cm        50          null        2.28

3 Answers 3

2

You can use an union for that.

select a,b,c from table A
union
select a,b,c from table B;

The number and type of columns in each select should be the same.

Sign up to request clarification or add additional context in comments.

1 Comment

tried union wont work....need some join or etc. just that can't figure out the logic yet.
0

Your Question seems incomplete but you can try following or this will help you to undesrstand how multiple table are used in query.

select t.pID, s.size s.stock d.quantity t.price 
from  tbl_product t,  tbl_product_size s, tbl_order_details d 
where  t.recID=s.pID  and d.pID=t.pID

1 Comment

this will product too many unrelated result. basically i want tbl_order_details data too be merge with tbl_product_size. however i will need to go through tbl_product as tbl_product can link the both tables.
0

This will do the trick

select t.pID, t.price, s.size, s.stock, d.quantity
from tbl_product t inner join tbl_product_size s on t.recID = s.pID
left outer join tbl_order_details d on t.pID = d.productCode and s.size = d.size;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.