I have a ''student" table I want to join with an "ID" table.
The "ID" table has 3 columns: "code" (I.e xxx), "sub code" (xxx-yy), and "type" (I.e, "aaa" or "bbb").
My issue is I want to left join by "xxx" when type = "aaa" and join by "xxx-yy" when type = "bbb".
How do I join with this condition?
I tried
select *
From students s
Left join ID as IDnum on s.code = IDnum.code and idnum = 'aaa'
Left join ID as IDnum on s.subcode = IDnum.code and idnum = ''bbb'
This gives me an error for using the table twice in my join
The "ID" table has 3 columns: "code" (I.e xxx), "sub code" (xxx-yy), and "type" (I.e, "aaa" or "bbb").
My issue is I want to left join by "xxx" when type = "aaa" and join by "xxx-yy" when type = "bbb".
How do I join with this condition?
I tried
select *
From students s
Left join ID as IDnum on s.code = IDnum.code and idnum = 'aaa'
Left join ID as IDnum on s.subcode = IDnum.code and idnum = ''bbb'
This gives me an error for using the table twice in my join
Last edited: