x
login about faq Site discussion (meta-askssc)

Simplify TSQL query

Hi Friends, I was trying to finetue a query and come across a piece of code written by some expert developer and I could not understand what the second clause in this query meant for.One in which he is using " 1>=" for count of join based on column of outer query
I cannot find the meaning of this query. Any view is appreciated.

SELECT COL1 ,

COL2 ,

COL3

FROM TAB1

 WHERE COL2=1 

AND 1>=

 (

    SELECT COUNT(*) 

    FROM TAB2

    WHERE    


           TAB2.P_COL='{D7079DEF-0FF2-42C3-85CD-2D357E096E9E}'

           AND 

          TAB2.COL2=TAB1.COl1

)

more ▼

asked Mar 16 '12 at 08:51 PM in Default

inder gravatar image

inder
201 9 16 20

Is there any way to rewrite this query without subquery

Mar 16 '12 at 09:03 PM inder
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

It looks to me as though the query is looking to return only items in Tab1 where there's at most one item in Tab2.

more ▼

answered Mar 16 '12 at 08:56 PM

ThomasRushton gravatar image

ThomasRushton ♦
29.1k 6 9 36

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x224

asked: Mar 16 '12 at 08:51 PM

Seen: 401 times

Last Updated: Mar 16 '12 at 09:34 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.