I’ve read a few threads related to this, but haven’t been able to pin down a solution that works for me – perhaps I’m misunderstanding some of the examples I’ve come across.
Here’s my existing query, which should help make sense of what I’m trying to accomplish;
SELECT type, refid, status, shortname, IsStore, IsProduct
FROM user_contributions c
WHERE UserID='#getuser.UserID#'
ORDER BY ID DESC
LIMIT 20
The values for ‘IsProduct’ and ‘IsStore’ are always either NULL or Yes – and each row will have one or the other.
Now, what I need to do is a Left Join on either the ‘stores’ table or ‘products’ table depending on the value of ‘IsStore’ or ‘IsProduct’ (still with me?). For example, if the value of IsStore is yes, I would add in LEFT JOIN Stores WHERE ID=refid
Assuming I need to keep the result fields consistent, I would use ‘AS title’ for either storename or productname to make output consistent.
I’m not sure I’ve explained this particularly well, so please ask for clarification if thats the case. Any help would be much appreciated!
Just add that condition to the join: