If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Problem nesting one SQL in another
hello to all
This is a general question about nesting one SQL in another. The example is just made up to help me understand. Start with 2 queries called qryA and qryB. qryA: SELECT tblP.PName, tblP.PNumber FROM tblP ORDER BY tblP.PNumber DESC, tblP.PName; qryB: SELECT DISTINCT tblP.PNumber FROM tblP ORDER BY tblP.PNumber DESC; In qryC, I want to incorporate qryB in qryA, something like qryC: SELECT tblP.PName, tblP.PNumber, (SELECT Count(*) FROM [qryB] ...etc This works fine. The next thing I want to do is replace the [qryB] in the line above with the SQL for qryB. Now comes my difficulty. qryB had its Query Properies/Unique Value set to 'Yes'. When I replace [qryB] with its SQL, how do I communicate that the Unique Value should be set to 'Yes' for this part of the SQL? thanks in advance -- cinnie |
#2
|
|||
|
|||
Problem nesting one SQL in another
Use the word DISTINCT after SELECT for the Unique Values property and
DISTINCTROW for the Unique Records property. You can notice that this word has already been added to the sql string for qryB. -- Sylvain Lafontaine, ing. MVP - Technologies Virtual-PC E-mail: sylvain aei ca (fill the blanks, no spam please) "cinnie" wrote in message ... hello to all This is a general question about nesting one SQL in another. The example is just made up to help me understand. Start with 2 queries called qryA and qryB. qryA: SELECT tblP.PName, tblP.PNumber FROM tblP ORDER BY tblP.PNumber DESC, tblP.PName; qryB: SELECT DISTINCT tblP.PNumber FROM tblP ORDER BY tblP.PNumber DESC; In qryC, I want to incorporate qryB in qryA, something like qryC: SELECT tblP.PName, tblP.PNumber, (SELECT Count(*) FROM [qryB] ...etc This works fine. The next thing I want to do is replace the [qryB] in the line above with the SQL for qryB. Now comes my difficulty. qryB had its Query Properies/Unique Value set to 'Yes'. When I replace [qryB] with its SQL, how do I communicate that the Unique Value should be set to 'Yes' for this part of the SQL? thanks in advance -- cinnie |
#3
|
|||
|
|||
Problem nesting one SQL in another
thanks Sylvain
I hadn't realizes that DISTINCT would automatically set this property. My mistake -- cinnie |
Thread Tools | |
Display Modes | |
|
|