Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #113

Re: I Need help with a query...

From Lutz Uhlmann <news@invalid.invalid>
Newsgroups comp.databases.ms-sqlserver
Subject Re: I Need help with a query...
Date 2011-04-05 11:50 +0200
Organization albasani.net
Message-ID <ineolg$hfs$1@news.albasani.net> (permalink)
References <ab761644-26ae-41c4-a599-acb60a80ae69@n12g2000yqc.googlegroups.com> <4d9ace2e$0$41110$e4fe514c@news.xs4all.nl> <e2ef8073-f5d0-4b63-85cd-e439f719202a@x1g2000yqb.googlegroups.com>

Show all headers | View raw


Am 05.04.2011 10:54, schrieb Alfaking:
> On 5 Apr, 10:09, Henk van den Berg<hvandenb...@xs4all.nl>  wrote:
>
>> Please post the query that you have used.
>
> In my idea this should be ok, but when I double-check the results,
> something goes wrong...
> no idea why

When I run

SELECT *
FROM dbo.table1
WHERE contr NOT IN (SELECT contr FROM dbo.table1 WHERE (type = 'T')
  GROUP BY contr)

i get this:
ID	Contr	Type
3	5555	W
5	7777	W
9	7777	W

I think this is the correct result!

Anyway there is also an alternative solution

SELECT t1.*
FROM dbo.table1 as t1 LEFT JOIN (SELECT contr FROM dbo.table1 WHERE
  (type = 'T') GROUP BY contr) AS t2 ON t1.contr=t2.contr
WHERE t2.contr IS NULL

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I Need help with a query... Alfaking <favia.alessandro@gmail.com> - 2011-04-05 00:30 -0700
  Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 10:09 +0200
    Re: I Need help with a query... Alfaking <favia.alessandro@gmail.com> - 2011-04-05 01:54 -0700
      Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 10:59 +0200
        Re: I Need help with a query... Alfaking <favia.alessandro@gmail.com> - 2011-04-05 02:14 -0700
          Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 11:29 +0200
      Re: I Need help with a query... Lutz Uhlmann <news@invalid.invalid> - 2011-04-05 11:50 +0200
        Re: I Need help with a query... Alfaking <favia.alessandro@gmail.com> - 2011-04-05 04:04 -0700
      Re: I Need help with a query... Alfaking <favia.alessandro@gmail.com> - 2011-04-05 03:57 -0700
        Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 13:07 +0200
  Re: I Need help with a query... "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-05 07:17 -0400
    Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 13:33 +0200
      Re: I Need help with a query... "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-05 07:40 -0400
        Re: I Need help with a query... Henk van den Berg <hvandenberg@xs4all.nl> - 2011-04-05 14:26 +0200
  Re: I Need help with a query... "Bob Barrows" <reb01501@NOSPAMyahoo.com> - 2011-04-05 07:38 -0400

csiph-web