max max - 6 months ago 40
SQL Question

triple join using sqlite

Let's say we have 3 tables:

table1: firstname, id

table2: id, lastname

table3: lastname, height

and we want to display: firstname, height

I'd likely use full join for that:

select firstname, height from
(select firstname, lastname ln from table1
full join table2 on table1.id=table2.id)
full join table3 on ln=table3.lastname


but in sqlite, full and right joins do not exist and I need to some how use union to get it.
Any ideas, how to do it?

Answer

Query:

SELECT firstname, height
FROM table1 INNER JOIN table2 ON table1.id=table2.id
            INNER JOIN table3 ON table2.lastname=table3.lastname
Comments