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 |
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-08-22 : 10:15:35
|
| Hi guys,i have 2 tables in a database. Table A contains:State City Employee_first Employee_Last AgeKarnataka Bangalore David Na 23Karnataka Bangalore Prakash Na 25Karnataka Mysore Naina Na 26Karnataka Mysore David Na 35Maharashtra Mumbai Parneet Na 24Maharashtra Mumbai Vikas Na 33Maharashtra Pune Amit Na 25Maharashtra Pune Amit Na 19Table B contains:State Employee_first Employee_Last SalaryKarnataka David Reinjal 15556Karnataka Prakash Mehra 15323Karnataka David Petre 36524Karnataka Kumar Mehra 56123Maharashtra Parneet Kaur 23315Maharashtra Vikas Pandey 35645Maharashtra Amit D'Souza 23564Maharashtra Amit Dhogla 12354The output should be:State City Employee_first Employee_Last Age SalaryKarnataka Bangalore David Reinjal 23 15556Karnataka Mysore David Mehra 35 56123Karnataka Mysore Naina Petre 26 36524Karnataka Bangalore Prakash Mehra 25 15323Maharashtra Mumbai Parneet Kaur 24 23315Maharashtra Mumbai Vikas Pandey 33 35645Maharashtra Pune Amit D'Souza 25 23564Maharashtra Pune Amit Dhogla 19 12354I tried using Inner join but it gave me a all together different output. how can i do using Union? Can anybody help me with this?Regards,David Reinjal |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-08-22 : 10:20:48
|
[code]SELECT a.State, a.City, a.Employee_first, a.Employee_Last, a.Age, b.SalaryFROM tablea a INNER JOIN tableb bON a.Employee_first = b.Employee_firstAND a.Employee_Last = b.Employee_Last[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-08-23 : 00:59:21
|
| thanks man. it worked. if i have a Table say A:State City Employee_first Employee_Last SalaryKarnataka Bangalore David Reinjal 15556Karnataka Mysore David Reinjal 56123Karnataka Mysore Naina Petre 36524Karnataka Bangalore Prakash Mehra 15323I want David Reinjal with max of salary along with rest of the output. How do i do that? I tried using:Where state = 'Karnataka and a.Salary IN ('Bangalore', 'Mysore)But it dint work. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2007-08-23 : 07:37:10
|
| Try normalizing the data first.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-08-23 : 07:48:48
|
[code]Where state = 'Karnataka and a.Salary IN ('Bangalore', 'Mysore')[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-08-23 : 08:22:26
|
| Where state = 'Karnataka and a.CITY IN ('Bangalore', 'Mysore')Jim |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-24 : 05:00:10
|
quote: Originally posted by jimf Where state = 'Karnataka and a.CITY IN ('Bangalore', 'Mysore')Jim
Good Correction on CITY MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|