Need help with a sub query:

hello, i need help writing a sub query... i have 2 tables, tab1 has 600 rows and tab2 has 271 rows so i need minus tab2 rows from tab1 and display the remaining 329 rows...
tab1 has 8 columns of which i need to display all rows, tab2 has 10 columns of which 6 column match  6 columns on i wrote something like this and it does not work...

select col1, col2, col3, col4, col5, col6, col7, col8, col8
from tab1 t1
where t1.col1 not in  (select       t2.col1
               from       tab1 t2, tab2 t3
                where       t2.col1=t3.col1 and
                                                   t2.col2=t3.col2 and
                                                  t2.col3=t3.col3 and
                               t2.col4=t3.col4 and

can you please help me with this sub query...
Who is Participating?
slightwv (䄆 Netminder)Connect With a Mentor Commented:
Maybe something like this?

select col1, col2, col3, col4, col5, col6, col7, col8 from tab1
where (col1, col2, col3, col4, col5,col6) in (
      select col1, col2, col3, col4, col5, col6 from tab2
sventhanConnect With a Mentor Commented:
Why do not you try

select wanted columns
select common_columns from tab1
select common_columns from tab2
) a, tab1
where your join condition
Rao_SAuthor Commented:
thank you both very much, i tried the one suggested by slightwv, this worked...
slightwv (䄆 Netminder) Commented:
oops.  I think mine should be NOT IN instead of IN.

... ,col6) NOT in (
      select ...
Rao_SAuthor Commented:
yes, that is right, i tried with the 'NOT IN' it worked..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.