ken
ken

Reputation: 11

MySQL INNER JOIN IN not getting right result

I have this query in my php and it seems to be fetching the wrong data set from my db.

$querystring = " 

SELECT a.*, 
       b.itemcolour, 
       b.itemcolourname 
FROM   itemorders AS a 
       INNER JOIN catalogueitemscolour AS b 
               ON a.colourid = b.colourid 
WHERE  a.colourid IN(SELECT colourid 
                     FROM   itemorders 
                     WHERE  orderid = 61) 

";

Here is a picture of my results

sample

Can I know why it's not selecting the specific orderID of 61?

Upvotes: 1

Views: 67

Answers (2)

Arpan Agrawal
Arpan Agrawal

Reputation: 1

Because you are not putting condition on orderID, rather putting it on colorID. What you actually want is this condition: WHERE a.orderID = 61.

Upvotes: 0

Fahmi
Fahmi

Reputation: 37473

You can try below -

SELECT a.*, b.itemColour,b.itemColourName FROM itemorders 
AS a INNER JOIN CatalogueItemsColour AS b ON a.colourID = b.colourID WHERE 
a.orderID = 61 

Upvotes: 1

Related Questions