sql - MYSQL Join Tables without key / index -


like title says, want join 2 tables without key compare.

mysql join tables without keys

this example descripes initial situation, looking cartesian product. want this

table 1: t1 red blue big small   table 2: t2 cat dog person 

the result should this:

red cat blue dog big person small null <--- can empty (not shown) 

is possible sql?

since mysql doesn't have row_id() function, have fake user-variable increment:

select adjective, noun (select @counter1 := @counter1+1 counter, adjective       table1, (select @counter1 := 0) init) t1 left join (select @counter2 := @counter2+1 counter, noun            table2, (select @counter2 := 0) init) t2 using (counter) 

demo

note assumes there more adjectives in table1 nouns in table2. if need allow either table smaller, need use full outer join. andriy m mentioned, mysql doesn't have built-in support this, if search or google should find ways code it.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -