MySQL's Select command using Union clause

Posted on 2008-11-05
Last Modified: 2012-06-27
I would like to query two tables have the following columns

table_one: title, content
table_two: content

As you can see, the "table_two" doesn't have the title column. Without creating a "title" column, is it possible add a "dummy" column so the following query will work with the UNION clause?

select title as t, content as c from table_one
select dummy_title as t, content as c from table_one;

The reason is that I am trying to create a search feature in a PHP script that has "Blog",  "News", "Comments" and other sections. So using the UNION clause I can combine the query but not all of them has the "title" field, for example "Comments", but I would also like to include "Comments" within the search.

Thank you.
Question by:santocki
    1 Comment
    LVL 142

    Accepted Solution

    select title as t, content as c from table_one
    select null as t, content as c from table_one;

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (…
    More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now