mysql - How can I display data from two unrelated tables? -


i have 2 unrelated tables in mysql database. want select , display data both of them.

as example, tables looks this: separate tables

i display results on site, organised alphabetically, this: results table

the id each table used refer photo of cat or dog. haven't had luck join statements, union work in scenario?

any appreciated.

select alpha, name, convert(cat_id, char(50)) cat_id, '' dog_id cat union select alpha, name, '' cat_id, convert(dog_id, char(50)) dog_id dog order alpha 

a few comments:

strictly speaking, if want show empty string missing cat or dog ids, need cast cat_id or dog_id columns char, because values in column need same type.

it not necessary wrap union query use order by , sort alpha column, rather can add order by end.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -