473,507 Members | 5,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determine table in union statement

160 New Member
hi to all

i am using union in select statement like this

Expand|Select|Wrap|Line Numbers
  1. mysql> SELECT * FROM t1 UNION SELECT * FROM t2 UNION SELECT * FROM t3;
  2.  
please tell me that is it possible that i can check value is come from which table (t1,t2 or t3)

let me know if i am not clear in my question
Jul 22 '09 #1
2 2208
waqasahmed996
160 New Member
i have done it by doing this

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.     articles.id AS id,
  3.     articles.title_article AS title,
  4.     articles.contents AS contents,
  5.     1 as tableid 
  6. FROM articles 
  7. WHERE 
  8.     (articles.status = '1' 
  9.         and (articles.title_article like '%political news%' or articles.contents LIKE '%political news%')
  10.     ) 
  11. UNION ALL 
  12. SELECT 
  13.     press_release.id,
  14.     press_release.title,
  15.     press_release.description,
  16.     2 as tableid 
  17. FROM press_release 
  18. WHERE 
  19.     (press_release.status = '1' 
  20.         and (press_release.title like '%political news%' or press_release.author LIKE '%political news%' or press_release.description like '%political news%')
  21.     ) 
  22. UNION 
  23. SELECT 
  24.     latest_news.id,
  25.     latest_news.title,
  26.     latest_news.news,
  27.     3 as tableid 
  28.  FROM latest_news 
  29.  WHERE 
  30.     (latest_news.status = '1' 
  31.         and (latest_news.title like '%political news%' or latest_news.news LIKE '%political news%')
  32.     ) 
  33. LIMIT 0, 50
Jul 22 '09 #2
Atli
5,058 Recognized Expert Expert
Hi.

I'm glad you found a solution!
Thank you for sharing it with us.
Jul 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3414
by: Stephen Patten | last post by:
Hi All, While in the process of building my table (40 or so Insert statments) can I then query ("select * from @Table_variable") and use the results up to theat point for another insert into...
1
2992
by: M Wells | last post by:
Hi All, Sorry if the subject line is too obscure -- I couldn't think of a way of describing this request. I have a table that contains approximately 1 million records. I want to be able to...
4
6586
by: SQLJunkie | last post by:
Here is an issue that has me stumped for the past few days. I have a table called MerchTran. Among various columns, the relevant columns for this issue are: FileDate datetime , SourceTable...
10
5586
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
8
17213
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ......
2
3236
by: kevinjbowman | last post by:
I am by no means a SQl Jedi as will be apparent by my question, but I can usually figure out a select statement on my own. I have one today though that really has me stumped. I am working in...
5
3815
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
1
9614
by: imani_technology_spam | last post by:
Right now, a client of mine has a T-SQL statement that does the following: 1) Create a temp table. 2) Populate temp table with data from one table using an INSERT statement. 3) Populate temp...
3
2832
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.