mysql - SQL full outer join or Union -


i have 2 different tables. 1 article table , gallery table. gallery contains multiple images , there table named images (which not shown here). images in images table link gallery table foreign key gallery_id.

now trying achieve is, in home page, need combined result of both articles , galleries. if article, thumbnail of article displayed , if gallery, last image gallery displayed.

|article    |  |-----------| |id         | |category_id| |title      | |slug       | |filename   | |body       | |created    | |modified   | 

|gallery| |-----------| |id         | |category_id| |title      | |slug       | |body       | |created    | |modified   | 

i using complex union query achieve it. how can sort results. possible use order by clause. can result achieved outer join ?

sounds outer join not apply here because want results in 1 column. joins make data in 2 columns, unions make data 1 column.

to sort can this

select  id              , category_id     , title           , slug            , filename        , body            , created         , modified (       select id                  , category_id         , title               , slug                , filename            , body                , created             , modified      article      union select id                  , category_id         , title               , slug                , body                , created             , modified      gallery ) allcombined order allcombined.title 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -