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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Two columns different tables

Author  Topic 

nunov
Starting Member

17 Posts

Posted - 2010-05-11 : 15:43:08
How do I check if every distinct atributes of one column of one table are in another column of another table?

Thank you for the attention

NV

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-11 : 15:45:20
SELECT *
FROM (SELECT DISTINCT Column1 FROM Table1) t1
WHERE NOT EXISTS (SELECT * FROM Table2 t2 WHERE t1.Column1 = t2.Column1)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nunov
Starting Member

17 Posts

Posted - 2010-05-11 : 16:15:46
Sorry actually in the problem I'm facing, I have to check if a combination of atributes os two diferent columns in one table exists e another one

I tried to do this, based in what you have answered, but it doesn't work

select * from (select numinq, numperg from perguntatxt) t where not exists (select numinq, numperg from utilresptxt u where t.numinq=u.numinq)

the variables are abreviations from portuguese so i'll try to explain the problem:

- numinq means number of enquiry and numperg means number of the question.
- utilresptxt is a table where I register answers from users
- perguntatxt is where the questions are registered

What I wanted to do was to check if a user had answered all the questions of an enquiry (by checking if there was any question registered that was not in the table of registered answers)


How should I do it?

NV
Go to Top of Page

nunov
Starting Member

17 Posts

Posted - 2010-05-11 : 18:20:31
I've done it thank you

NV
Go to Top of Page
   

- Advertisement -