A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

SubQuery



 
 
Thread Tools Display Modes
  #1  
Old October 19th, 2009, 05:07 PM posted to microsoft.public.access.forms
Abe Katz
external usenet poster
 
Posts: 43
Default SubQuery

Hello All,

I need a list from all the Items in the Inventory, the last date each item
was last sold, and the qty sold.
Doug Steele told me to use a subquery, it works fine with one table but when
I have a Header and a Detail table and using the INNER JOIN, the system
doesn't let me add the aliases table name (AS A). Error msg "Syntax error
missing operator in query expression".

This is my code,
SELECT [Invoice Detail].StyleNo, Invoice.Date AS DateLastInv, Sum([Invoice
Detail].Qty) AS QtyInv
FROM Invoice INNER JOIN [Invoice Detail] ON Invoice.InvoiceNo = [Invoice
Detail].InvoiceNo AS A (AS A, error message)
GROUP BY [Invoice Detail].StyleNo, Invoice.Date
HAVING (((Invoice.Date) In (SELECT Max(Date) FROM [Invoice] WHERE [Invoice
Detail].StyleNo=A.StyleNo)));

Please let me know
Thank you
abe


  #2  
Old October 20th, 2009, 04:36 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default SubQuery

Abe -

You don't really need the alias, but you can use it. To use the 'AS A' in
the FROM section of a SQL statement, it must appear after a table name, thus
giving the table an alias name. If you want the Invoice table to be
referenced as A, then the SQL should be this:

SELECT [Invoice Detail].StyleNo, Invoice.Date AS DateLastInv, Sum([Invoice
Detail].Qty) AS QtyInv
FROM Invoice AS A INNER JOIN [Invoice Detail] ON Invoice.InvoiceNo = [Invoice
Detail].InvoiceNo
GROUP BY [Invoice Detail].StyleNo, Invoice.Date
HAVING (((Invoice.Date) In (SELECT Max(Date) FROM [Invoice] WHERE [Invoice
Detail].StyleNo=A.StyleNo)));


--
Daryl S


"Abe Katz" wrote:

Hello All,

I need a list from all the Items in the Inventory, the last date each item
was last sold, and the qty sold.
Doug Steele told me to use a subquery, it works fine with one table but when
I have a Header and a Detail table and using the INNER JOIN, the system
doesn't let me add the aliases table name (AS A). Error msg "Syntax error
missing operator in query expression".

This is my code,
SELECT [Invoice Detail].StyleNo, Invoice.Date AS DateLastInv, Sum([Invoice
Detail].Qty) AS QtyInv
FROM Invoice INNER JOIN [Invoice Detail] ON Invoice.InvoiceNo = [Invoice
Detail].InvoiceNo AS A (AS A, error message)
GROUP BY [Invoice Detail].StyleNo, Invoice.Date
HAVING (((Invoice.Date) In (SELECT Max(Date) FROM [Invoice] WHERE [Invoice
Detail].StyleNo=A.StyleNo)));

Please let me know
Thank you
abe


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:17 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.