MikeBroski MikeBroski - 6 months ago 11
MySQL Question

INNER, OUTER OR RIGHT JOIN with 3 tables where one has same PK as the joining one but 1st doesn't

Hello I am currently trying to combine, 3 types of tables. I have mange to do it with 2 that have same values but what happends when you want the a 3rd table that has same pk as second but not first? And I hit a giant brick wall.... how do I solve this issue?

SELECT xxx.orderid, xxx.ordertime,xxx2.produdct, xxx2.product type, xxx3.priscut xx3.pricename FROM xxx
INNER JOIN xxx2 ON xxx.orderid= xxx2.orderid
RIGHT JOIN xxx3 ON xxx2.productid = xx3.productid;


My Best Wishes, Mike

Answer

Simply use inner join

SELECT 
 xxx.orderid
, xxx.ordertime
,xxx2.produdct
, xxx2.producttype
, xxx3.priscut xx3.pricename 
FROM xxx
INNER JOIN xxx2 ON xxx.orderid= xxx2.orderid
INNER JOIN xxx3 ON xxx2.productid = xx3.productid;
Comments