Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: open

Message Too Old, No Replies

Need help with a JOIN

Joining 3 tables

     
2:17 pm on Nov 26, 2011 (gmt 0)



Maybe a lame excuse but I need help because I have a horrible flu with a headache, watery eyes and a deadline. And JOINs have never been a strong suit of mine so after staring at this problem for 4 hours now I admit I need help.

I have 3 tables:

product
id
name
type
status

categories
id
parent
cat

xref
id
catID
prodID

I need to have a list of all the categories (can be doubles) of all products where status=X and type=Y

What I have sofar is:

SELECT * FROM xref AS x
LEFT JOIN categories AS c ON x.catID = c.id
LEFT JOIN product AS p ON x.prodID = p.id WHERE status = X AND type = Y;


But it does not seem to work as I expect?
Can anyone help me out here please? Thank you.
9:57 am on Nov 27, 2011 (gmt 0)



Because of a rewrite of another part of my code I now only need a 2-table join.
With the same tables as above I now have:

SELECT x.catID FROM xref AS x
LEFT JOIN product AS p
ON x.prodID = p.id
WHERE a.status = '{$status}' AND a.type = '{$type}' AND x.prodID = '{$productID}'


But I get no results back?
I hate JOINs, lol.
10:56 am on Nov 27, 2011 (gmt 0)



Ok, never mind. There was nothing wrong with neither query, it was another stupid (no doubt flu related, yeah right) mistake later on in my code (I expected the result to be available before I executed it, lol).
 

Featured Threads

Hot Threads This Week

Hot Threads This Month