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 |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2010-06-18 : 08:07:28
|
HiI have a table with user information, the table have 4 Columns, UserID, UserName, Company and Country. The data can look like this...UserID UserName Company Country1 Mark Smith Company 1 USA2 Mark Smith Company 1 Mexico3 John Low Company 1 USA4 Mark Low Company 1 Mexico5 Anna Low Company 1 Mexico I need to filter out user that work in diferent countires, but the user must occur more than one time, so based on this all records but record 5 should be displayed from the data above. Beacuse UserID 5 only work at one place (company 1 in Mexico) I have no idea on how to solve this, can someone please help me? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-18 : 08:48:34
|
| Tryselect * from tablewhere username in(select username from tablegroup by usernamehaving count(distinct compnay)>1)MadhivananFailing to plan is Planning to fail |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2010-06-18 : 09:05:05
|
| Hiwhen I run this as a view in sql server management studio, this code is generated...SELECT ID, UserName, Password, UserRealName, Email, UserLevelFROM dbo.tbl_LoginWHERE (UserRealName IN (SELECT UserRealName FROM dbo.tbl_Login AS tbl_Login_1 GROUP BY UserRealName HAVING (COUNT(DISTINCT Country) > 1)))But I also get a error: Invalid column name "Country", why is that? The country column do exsit |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-18 : 09:08:05
|
| In whcih table the column is available?MadhivananFailing to plan is Planning to fail |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2010-06-18 : 09:17:29
|
| HiAll information/columns is in tbl_Login |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-18 : 10:09:46
|
quote: Originally posted by magmo HiAll information/columns is in tbl_Login
Does it mean country is one of the columns of tbl_login?MadhivananFailing to plan is Planning to fail |
 |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2010-06-18 : 10:28:57
|
| Yes it does |
 |
|
|
|
|
|
|
|