Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345

Query Expand / Collapse
Author
Message
Posted Saturday, May 17, 2008 11:59 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, May 25, 2008 11:04 PM
Points: 30, Visits: 11
Hi there Gurus!

I thought I was a naive beyond imagination 'cos I completely missed the purpose of that query!
Looks like something framed on a particularly boring afternoon :)

We need better than that if we are to learn!

The naïveté
Post #502586
Posted Tuesday, May 20, 2008 4:14 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 9:33 AM
Points: 449, Visits: 1,866
Hi There,

I agree that the query would work, but only on the premise that only one of the tables had the column customerid. To say that any of the two tables could have the customerid would require having an alias to resolve the column.

My 2 cents

:)



Regards,

WilliamD
Post #503430
Posted Friday, May 23, 2008 8:56 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, January 27, 2014 10:14 AM
Points: 1,322, Visits: 1,091
I don't think that the fact that the query compiles is a bug per se. It compiles because subqueries must have access to their parent in order to create correlated queries. The compiler can't assume what that correlation is going to look like so if it can resolve the name it will. Think of:
select Count(*)
FROM ClientTable
where Exists (SELECT * FROM OrderTable where PKClientID = FKClientID)


Now, while I consider it bad to have different names for the same information, I 've seen this type of design. The Compiler must be able to compile the above because it is valid. Therefore it also must be able to compile the syntactically correct, but bizarre:
select * from ClientTable, Contracts
Where clientid in (select contractclientid where overdue > 30)

As far as the compiler is concerned as long as the names contractclientid and overdue are resolvable then it is a syntactically valid statement.
--
JimFive
Post #505936
Posted Tuesday, July 8, 2008 5:27 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, May 23, 2012 6:06 PM
Points: 40, Visits: 3

Query

What will happen if following query get executed:

select CategoryID, Quantity, Price
from Customer c, SalesOrderDetail sod
where sod.clientid in (select customerid where pricingplan='X')

In this Query options nothing was spoken about pricingplan column.
If pricingplan column is not part of either of the tables then the query will end up in Error. Why not the Third option is right answer for this Question in this scenario?? :)
Post #529906
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse