5
I have a question on how to ask a question to the database.
Suppose I have two tables with slightly different structures
Table1
id tipoA data
0 A '21/12/14'
Table2
id tipoB data
1 B '24/12/14'
Upshot
id tipoA tipoB data
0 A B '21/12/14'
1 A B '24/12/14'
The expected
id tipoA tipoB data
0 A 0 '21/12/14'
1 0 B '24/12/14'
I simply want that if the field does not exist to not fill it or put a 0 or ''
I did:
SELECT * FROM tabela1, tabela2;
but this command does not return the expected result. As I should do?
If did
Select id, coalesce(tabela1.tipoA, 0) as tipoA, coalesce(tabela.tipoB, 0) as tipoB From tabela1, tabela2
But, I think this command is simply asking each table separately if it has the null field, and it will never happen.– lazyFox
Does this query work? I mean, if the two tables have the fields
id
anddata
, Mysql will choke because the references toid
anddata
are ambiguous.– user25930
I forced the error in the query.
– Diego Souza