Joins with multiple conditions

Joins with multiple conditions

meekaakumeekaaku Posts: 11Questions: 4Answers: 0

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

Answers

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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

  • zeinerrjzeinerrj Posts: 11Questions: 1Answers: 2
    edited August 2015

    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

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    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

  • meekaakumeekaaku Posts: 11Questions: 4Answers: 0

    thanks. will try that

This discussion has been closed.