Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql in MS Access and syntax critique 1

Status
Not open for further replies.
Feb 12, 2003
45
0
0
US
Could anyone critique this syntax for me?

SELECT dpch.pname, dpch.pnum, (select count(*) from proquick where proquick.rph=dpch.pname) as expr1 from dpch;

Anyone see any problem with this? I'm trying to get a count of proquick instances per pname's in dpch.
Thanks,
Chris
 
Why not simply an aggregate query ?
SELECT dpch.pname, dpch.pnum, COUNT(*) AS expr1
FROM dpch INNER JOIN proquick ON dpch.pname=proquick.rph GROUP BY dpch.pname, dpch.pnum

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
Thanks for the response - but that code gives me an aggregation error with PNAME. Only problem I'm really having at this point is getting the order by to work. - using ORDER BY "Expr1" ASC;
but it's not ordering the results...
Thanks,
Chris

 
ORDER BY 3

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmmm... for some reason it doesn't work. I works if I use order by 2 but not for order by 3... thoughts?
Thanks,
Chris
 
Any chance you could post your actual SQL code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It's the code I posted above (on the first post). I launch the query directly to view the data - and I can sort by column 3 - and it remembers how I sorted the 'view'. I can change the SQL to say sort by 1 and the launching SQL directly still bring up the previous view settings. Thoughts?
Thanks,
Chris
 
Please note - when I say I sort by column three - I mean I right click on the column, select sort by ascending... and it sorts.
 
aggregation error with PNAME
Is by chance PNAME a memo ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No - it's not a memo - just a standard text field.
I'm stumped...
 
what about this --
Code:
SELECT pname
     , pnum
     , expr1 
  from (   
       SELECT dpch.pname
            , dpch.pnum
            , ( select count(*) 
                  from proquick 
                 where proquick.rph
                     = dpch.pname) as expr1 
        from dpch
       ) as data
order by expr1

r937.com | rudy.ca
 
r937,
That works great! It never ceases to amaze me how seemingly little innocuous syntax variations can have such a profound effect on a project! Is the key to this subquery the "expr1 from " component?
Thanks,
Chris


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top