Subqueries in Access (1 Viewer)

Ben_Entrew

Registered User.
Local time
Yesterday, 16:48
Joined
Dec 3, 2013
Messages
177
Hello,

I try to execute following subquery:

DoCmd.RunSQL "SELECT DISTINCT Q_PRICES.Material, Q_PRICES.Product_Class INTO TEST " & _
"FROM Q_PRICES " & _
"WHERE " & _
"(SELECT Q_PRICES.Material " & _
"FROM Q_PRICES " & _
"WHERE Q_PRICES.Valid_to Like '*2017' " & _
"GROUP BY Q_PRICES.Material " & _
"HAVING Count(Q_PRICES.Product_Class)>1) " & _
"GROUP BY Q_PRICES.Material, Q_PRICES.Product_Class"

It replies me this warning message:

At most one record can be returned by this subquery

Basically I wanna find out if there are material numbers with more than one product class name. This shouldn't occur in our data.

Any clue how I can rewrite this?

Thank you.

Regards,
Ben
 

Ranman256

Well-known member
Local time
Yesterday, 19:48
Joined
Apr 9, 2015
Messages
4,339
dont write sql, create a query, bind the query to the sub form.
see if this works. It may give errors why.
 

sneuberg

AWF VIP
Local time
Yesterday, 16:48
Joined
Oct 17, 2014
Messages
3,506
If the subquery can produce more than one result maybe you need to use WHERE IN rather than just WHERE. Some like:
Code:
DoCmd.RunSQL "SELECT DISTINCT Q_PRICES.Material, Q_PRICES.Product_Class INTO TEST " & _
"FROM Q_PRICES " & _
"WHERE[COLOR="Blue"] Q_PRICES.Material IN[/COLOR] " & _
...
in place of

Code:
DoCmd.RunSQL "SELECT DISTINCT Q_PRICES.Material, Q_PRICES.Product_Class INTO TEST " & _
"FROM Q_PRICES " & _
"WHERE " & _
...
 

Users who are viewing this thread

Top Bottom