Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vemulavijay
Starting Member
32 Posts |
Posted - 2006-01-20 : 06:57:07
|
| hello, i am having 5 tables. the table contains 2 feilds, id and name.there are 100 records in each table. so totally there are 500 records. my task is to search the unique id say 103950 in all tables and find in which table the id exists and get the row no of that particular matched id.i am looking for a query in this regard.thanks,vemula vijay |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-20 : 07:15:19
|
| Check if this helps youCreate an identity column in the tables that will give you the record no and query like this..(select identitycol,'Table 1' from table1 where id = 103950 )union (select identitycol ,'Table 2' from table2 where id = 103950 )union (select identitycol ,'Table 3' from table3 where id = 103950 )union (select identitycol ,'Table 4' from table4 where id = 103950 )union (select identitycol ,'Table 5' from table5 where id = 103950 ) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-20 : 07:46:35
|
| Also use Union All for efficiencyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|