Convert LEFT JOIN SQL query to Ecto query

Hi all,

I have a simple query but I don’t know how should I convert it to ecto query?

SELECT anklets.id, anklets.model, customer.id FROM 
anklets LEFT JOIN customers ON anklets.id = customers.anklet_id 
WHERE customers.id is NULL

Would you please help me to implement currect Ecto query?

I found the solution:

query = from a in Anklet, 
        left_join: c in Customer, 
        on: a.id == c.anklet_id, 
        select: {a.id, a.serial_num, c.id}, 
        where: is_nil c.id

Hi @alishir, give it a shot with something like this:

from(a in "anklets"
  left_join: c in "customers",
  on: a.id == c.anklet_id,
  where: is_nil(s.id),
  select: {a.id, a.model, c.id}
)
1 Like

Thanks for your guidance.

1 Like