Search code examples
phpmysqlsqlyog

Combine two columns into one


How can I combine two columns into one. For example, I have one table named "posts" and other "posts_shared"

"posts" have these columns:

po_id
po_id_user

"posts_shared" have these columns:

ps_post_id 
ps_shared_by

What I need is to bring all the data from "posts" and "posts_shared" in only one column. How can i do this?


Solution

  • If you mean combining posts.po_id posts_shared.ps_post_id into one column and the same with po_id_user and ps_shared_by then use UNION clause in your SQL query.

    SELECT po_id, po_id_user
    FROM  posts
    UNION
    SELECT ps_post_id, ps_shared_by
    FROM  posts_shared;
    

    But in order to make UNION possible, corresponding fields in your posts and posts_shared tables should have identical types.