The version is 5.0.
BTW, this query also doesn't error:
select m.* from
(select a. * from
(select * from ap4prod) as a
inner join
(select distinct prod from pr7prod) as b
on a. prod = b.prod) as m
Main Topics
Browse All TopicsExperts,
this works:
select * from
(select * from ap4prod) as a
inner join
(select distinct prod from pr7prod) as b
on a. prod = b.prod
but this doesn't - could you please advise correct syntax. the error message is 'you have an error in your SQL syntax'
select m. * from
((select * from ap4prod) as a
inner join
(select distinct prod from pr7prod) as b
on a. prod = b.prod) as m
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks so much for the validation, and alternate logic. The alternate query is running, but is slower than the other way (there's no index on prod in pr7prod). Am not familiar with the structure of the alternate query - do you mind explaining briefly please (sure does look impressive). For instance:
-is 'ap4prod a' shorthand for 'ap4prod as a'?
-what is the 'select null from...' doing?
-what is the 'where exists' checking?
>-is 'ap4prod a' shorthand for 'ap4prod as a'?
yes
>-what is the 'select null from...' doing?
pure syntax, as the EXISTS() checks if the subquery returns a row or not, it does not matter what column values are returned...
>-what is the 'where exists' checking?
the exists(<subquery>) function checks if the subquery returns rows or not, and returns true if at least 1 row would be returned, and false if no rows are returned.
now, look at the condition in the <subquery>:
where a.prod = b.prod
as you see, the table from the subquery (pr7prod) is "joined" there with the table from the main query (ap4prod). this technique is called "correlated" subquery.
the main advantage of this method is that the EXISTS() will stop looking one it found a matching row, it does not have to perform the DISTINCT, or find all matching rows.
>The alternate query is running, but is slower than the other way (there's no index on prod in pr7prod).
then, create on:
CREATE INDEX IDX_PR7PROD ON PR7PROD ( prod );
and see the difference.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-12-26 at 02:43:31ID: 20528835
what version of MySQL are you using?
subqueries like that are not possible with MySQL 4.0 or lower...