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
 SQL

Author  Topic 

dg19
Starting Member

15 Posts

Posted - 2010-08-02 : 10:18:19
Dear All,

I am new to this form and to SQL. My problem is that i want to exclude the result of an sql query from another sql query.

for e.g

First Query:

Select rulesonbatch.describe_rule as 'Details' from rulesonbatch
inner join rulesonclient on rulesonbatch.id_rule = rulesonclient.id_rule
where rulesonclient.code_client=208


Second Query:

Select rulesonbatch.describe_rule as 'Details' from rulesonbatch


I would like to exclude the result of the first query from the second query. Is it possible?

Thanks in advance.

Regards,

Amit

dg19
Starting Member

15 Posts

Posted - 2010-08-02 : 10:37:09
Hi,

Does any one have an answer.

Pleeeeeaaase, This Query is blocking the development of my program.

thanks,

Amit
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-02 : 10:39:27
This?

Select rb.describe_rule as 'Details' from rulesonbatch as rb
where not exists(
Select *
from rulesonbatch rb1
inner join rulesonclient rc on rb1.id_rule = rc.id_rule
where rc.code_client=208 and rb1.id_rule=rb.id_rule)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Devart
Posting Yak Master

102 Posts

Posted - 2010-08-02 : 10:42:58
Hello,

You can try this:

SELECT
rulesonbatch.describe_rule as 'Details'
FROM rulesonbatch
LEFT JOIN (SELECT * FROM rulesonclient WHERE code_client=208) rsn
ON rulesonbatch.id_rule = rsn.id_rule
WHERE
rsn.id_rule IS NULL

Best regards,

Devart,
SQL Server Tools:
dbForge Schema Compare
dbForge Data Compare
dbForge Query Builder
Go to Top of Page

dg19
Starting Member

15 Posts

Posted - 2010-08-02 : 10:43:22
Thanks webfred,

I know it stupid.

But you really got me out of a mess.

Regards,

Amit
Go to Top of Page

dg19
Starting Member

15 Posts

Posted - 2010-08-02 : 10:47:29
Thanks to you too Devart,

Yours work really good too.

Regards,

Amit
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-02 : 10:48:12
quote:
Originally posted by dg19

Thanks webfred,

I know it stupid.

But you really got me out of a mess.

Regards,

Amit


welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -