[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQL's Select command using Union clause

Posted on 2008-11-05
1
Medium Priority
?
459 Views
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
union
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.
0
Comment
Question by:santocki
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 22890032
yes:

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

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 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