| Author |
Topic |
|
pauls09
Starting Member
3 Posts |
Posted - 2012-01-04 : 00:05:12
|
| I'm experimenting with SQL Server, now I'm trying to do the following: let's say that the 'user' table has 100 entries (with id and login) and the 'login' or access table has 3000 (only id), how can I use the select command to get a list of all users that never logged in? thanks you any help. |
|
|
ntizer
Starting Member
6 Posts |
Posted - 2012-01-04 : 00:15:24
|
| u mean dat User table contains entries of users currently logged in?can u elaborate more? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-04 : 04:31:24
|
| Please post table definitions, sample data and expected results. I can't guess what your table design looks like.--Gail ShawSQL Server MVP |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-01-04 : 04:45:01
|
| Starts with thisselect userid from users as u where not exists(select * from logins where userid=u.userid)MadhivananFailing to plan is Planning to fail |
 |
|
|
pauls09
Starting Member
3 Posts |
Posted - 2012-01-04 : 10:27:47
|
| thank you for the replies so far... I will elaborate moree.g.user table--------------userid | login1 | user12 | user23 | user34 | user45 | user5... | ...logins------userid2276575...How can I use select to report all users that have never logged in the system... |
 |
|
|
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2012-01-04 : 10:51:09
|
| SELECT userid from usertableexceptSELECT userid from loginsThis will only work in SQL server 2005 onwards |
 |
|
|
pauls09
Starting Member
3 Posts |
Posted - 2012-01-04 : 11:19:23
|
| thank you, I was reading more about SQL syntax and its much clear now. |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-01-04 : 12:58:12
|
| SELECT <column list> FROM users where UserID NOT IN (SELECT UserID FROM Logins)--Gail ShawSQL Server MVP |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-01-04 : 13:19:58
|
Here is another way using a LEFT OUTER JOIN:SELECT <column list> FROM Users LEFT OUTER JOIN Logins ON Useers.UserID = Logins.UserIDWHERE Logins.UserID IS NULL |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|