lundi 2 mai 2016

SQLite3 - use value (string) from table 1 to refer columns of another table

I have two tables:
T1:

id  name  field serial# 
1   A1    xx    123 
2   A1    yy    123
3   A1    zz    123
4   A2    xx    124
5   A2    yy    124
6   A2    zz    124

T2:
serial#   xx  yy  zz 
123       0   1   1
124       1   0   1

I want to write a query such that the result table would look like:

id  name  field serial#
1   A1    yy    123
2   A1    zz    123
3   A2    xx    124
4   A2    zz    124

I tried to write a query which looks like:

select * from T1, T2
from ...
where T2.(T1.field) <> 0  <-- This is where I never get the syntax right
...

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire