SQL Server - results from two tables that only exist in one -



SQL Server - results from two tables that only exist in one -

i have 2 tables:

users messages --------- --------- [ firstname ] [ firstname ] [ lastname ] [ lastname ] [ ssn ] [ ssn ] [ message ]

i have next query microsoft sql:

select t2.firstname, t2.lastname, t2.ssn [messages] t1 bring together [user] t2 on t1.ssn = t2.ssn

what gives me result exist on both tables. need to pull records messages table if ssn not exist on users table. know there sec step involved can't figure out.

update: still not work. have absolutely no null(s) in database. records populated data. need records messages table not exist in users table.

example:

users [ 1 john smith 111-11-1111 ] users [ 2 jim tompson 999-99-9999 ] messages [ 1 john smith 111-11-1111 ] messages [ 2 jim tompson 999-99-9999 ] messages [ 3 angelina jolie 888-88-8888 ] the result be: [ 3 angelina jolie 888-88-8888 ]

try this:

select t2.firstname, t2.lastname, t2.ssn [messages] t2 t2.ssn not in ( select distinct ssn [users] )

sql sql-server database

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -