Joins with multiple conditions
Joins with multiple conditions
SELECT p.product_id, p.name, pa.text FROM product p
LEFT JOIN product_attribute pa ON pa.product_id = p.product_id
AND pa.attribute_id = 12
for a query like above, how do i use the leftJoin to join on mutiple conditions? I can do the join
on product_id but not both.
if i use where (as suggested here https://datatables.net/forums/discussion/26870/left-join-two-fields) it
doesnt join on the NULL values of pa.text, ie it works like INNER joins
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
This is with Editor is it? Unfortunately the Editor libraries do not currently support multiple conditions for the left join. Sorry - this is something that I hope to implement in future, but it isn't available yet.
Allan
Hello meekaaku,
Try changing your driver table and rewrite the query as:
SELECT p.product_id, p.name, pa.text FROM product_attribute pa
LEFT JOIN product p ON pa.product_id = p.product_id
WHERE pa.attribute_id = 12
Doh yes, I should have realised that. Since the second condition is applied with a static value, it can just be used as a general condition. Thanks for your post @zeinerrj.
Allan
thanks. will try that