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 |
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2009-12-09 : 03:33:49
|
i have 4 tables each table having 4 columns.Tbl_First First Name | White1 | Blac1 | Red1Tbl_SecondLast Name | White2 | Blac2 | Red2Tbl_ThirdMiddle Name | White3 | Blac3 | Red3Tbl_FourthZip Code | White4 | Blac4 | Red4 All the tables contains numeric data except for name coumn. I want to retrive a data from all tables by sending parameters of one record(.ie firstname, lastname, middlename and his zipcode). we will get four rows from all tables. Now i want to find out which White contains the largest value(i.e Among white1,white2,white3,white4)is there any way to write a single query for this reqt. ?OrAs i explanied above, need to write 4 quereis to retrive data from 4 tables and then check with .net code to find the largest one ?developer :) |
|
|
vikky
Yak Posting Veteran
54 Posts |
Posted - 2009-12-09 : 03:41:09
|
| Hi,select max(white) from (select white1 as white from Tbl_First where First Name = First Name union allselect white2 as white from Tbl_Second where Last Name = Last Name union allselect white3 as white from Tbl_Third where Middle Name = Middle Name union allselect white4 as white from Tbl_Fourth where Zip Code = Zip Code ) as tThanks,vikky. |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-12-09 : 03:52:36
|
quote: Originally posted by vikky Hi,select max(white) from (select white1 as white from Tbl_First where First Name = First Name union allselect white2 as white from Tbl_Second where Last Name = Last Name union allselect white3 as white from Tbl_Third where Middle Name = Middle Name union allselect white4 as white from Tbl_Fourth where Zip Code = Zip Code ) as tThanks,vikky.
Please check the column names....-------------------------R... |
 |
|
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2009-12-09 : 04:10:05
|
Hi Vikky,Thanks for Query... It works perfect. quote: Originally posted by vikky Hi,select max(white) from (select white1 as white from Tbl_First where First Name = First Name union allselect white2 as white from Tbl_Second where Last Name = Last Name union allselect white3 as white from Tbl_Third where Middle Name = Middle Name union allselect white4 as white from Tbl_Fourth where Zip Code = Zip Code ) as tThanks,vikky.
developer :) |
 |
|
|
vikky
Yak Posting Veteran
54 Posts |
Posted - 2009-12-09 : 05:28:38
|
| ok ur welcome |
 |
|
|
|
|
|
|
|