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 |
hthuong
Starting Member
1 Post |
Posted - 2012-11-10 : 19:51:10
|
I have two tableTable loginaccount_id | name========================12345 | thuong112346 | thuong212347 | thuong3Table characcount_id | char========================12345 | name112345 | name212345 | name312345 | name4 I want to select ...SQL 1SELECT account_id FORM char WHERE char='name1'I will have result12345SQL 2SELECT login.account_id, login.name, char.char WHERE login.account_id=char .account_id GROUP BY login.account_id , login.name, char.account_id, char.char HAVING login.account_id = 12345Resultaccount_id | name | char 12345 | thuong1 | name1 12345 | thuong1 | name2 12345 | thuong1 | name3 How i select it with 1 one sql query? |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-11-11 : 07:21:42
|
Seems like there is something not quite right with the data or the setup - although I am not able to tell you what it is without understanding the business logic better. May be a query such as this is what you are looking for?select a.account_id, a.name, b.charfrom tableA a inner join tableB b on a.account_Id = b.account_idwhere a.account_id in ( select x.account_id from tableB x where x.char = 'name1' ) |
|
|
|
|
|