PDA

View Full Version : Adding missing rows in table in 1 select (+ join) command.


huckfinn
07-11-2003, 03:26 PM
Hi all! Here's what I need to do :

I have two tables :
A B
a b c d
---- ----
1 z 1 k
2 x 5 l
3 c 6 j

I need a SELECT with JOIN that would give me :
A
a b
----
1 z
2 x
3 c
5 NULL
6 NULL

so I need to add the missing rows from the A.a and B.c JOIN,
how can I do that ?

I can't use a Union 'cause I can't use MySQL version 4.

Thanks,

Simon

raf
07-11-2003, 10:37 PM
By using an outer join, you can find unmatched questions. http://www.mysql.com/doc/en/JOIN.html

But i completely don't understand the example. Say you have this
Table 1
VarA | VarB
1 | a
2 | c
3 | g
Var B = foreign key to table 2

Table 2
VarC | VarD
a | bla
b | blabla
c | test
d | ddd
e | bbvvvvvv
f | nnnnnnn
g | nnnnnnn

Say you now want a query that returns all values for VarC and the joined values for VarA (so you'll have at least the same number of records as in table 2

Then you can use

select Table2.VarC, Table1.VarA from table1 right join table2 on table1.varD=table2.varC


But like ai said, i don't understand your question so i might be completely off