rokastokas
rokastokas

Reputation: 77

How to get all records from two tables?

Lets say we have two simple tables like:

**table1**                      **table2**
Nr   Color                      Id   Type
1    green                      43   metal
2    red                        52   glass
3    black                     
4    white 

What I want to retrieve in my query is:

Nr   Color   Id   Type
1    green   43   metal
2    red     52   glass
3    black
4    white

Please help me.

Upvotes: 1

Views: 78

Answers (1)

webGautam
webGautam

Reputation: 565

Its simply not possible, you need to do some trick here..

select Nr, Color, Id, Type
from (select @counter1 := @counter1+1 as counter, Nr, Color
      from table1, (select @counter1 := 0) init) t1
left join (select @counter2 := @counter2+1 as counter, Id, Type
           from table2, (select @counter2 := 0) init) t2
using (counter)

Produce result

Nr   Color   Id   Type
1    green   43   metal
2    red     52   glass
3    black
4    white

But as comment suggest best practice is define relation between tables.

Upvotes: 1

Related Questions