Author |
Topic |
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-04 : 17:30:38
|
Can you show me an example of subquery nesting? Thanks |
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-04 : 18:43:21
|
So I came up with the code below, is this a legit nested subquery?It returns no rows but I get no error messages.SELECT DISTINCT c.ResellerName FROM dbo.DimReseller c JOIN dbo.FactResellerSales eON e.ResellerKey = c.ResellerKey WHERE ProductLine IN (SELECT ProductLine FROM dbo.DimProductWHERE StandardCost IN (SELECT ProductStandardCost FROM dbo.FactInternetSalesWHERE ProductStandardCost > 1000)) |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2014-03-05 : 01:47:52
|
A Subquery is a query within another SQL query , embedded within the WHERE clause. So , yes it looks like a legit query. There are some subquery rules which need to be followedThey are useful for completing more complex queriesJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-05 : 08:27:06
|
Thanks jacky, can you take a look at above code and see if it's qualified as nested subquery? |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2014-03-05 : 08:37:04
|
I believe so - a query with a subquery.CheersMIK |
|
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-05 : 08:41:27
|
Thanks MIK |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2014-03-05 : 09:44:18
|
you're welcome!CheersMIK |
|
|
maunishq
Yak Posting Veteran
71 Posts |
Posted - 2014-03-05 : 10:26:27
|
It returns error message when there is error in your syntax or when the object you referring does not exist in that particular schema/db/table. It pulls 0 rows means your query is right but there is nothing that satisfy your logic.=======================Not an Expert, Just a learner.!_(M)_! |
|
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-05 : 10:45:44
|
thanks maunishq |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2014-03-07 : 01:48:09
|
quote: Originally posted by rv498 Thanks jacky, can you take a look at above code and see if it's qualified as nested subquery?
Yes ,it does as a nested query - based on the definition I postedJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
|