How to create a proper Nested select statement in mysql

I am getting the error message "subquery returns more than one row" with the code below? I am trying to select only those records from the table shosondemand who's id is in the tmp_shoe_id table.   Whats wrong with the code?
select distinct * from shosondemand where id = (select *  from tmp_shoe_id);

Open in new window

DAN2011Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Hi Dan,

There are several ways to do this.  Most common is to use IN.

select distinct * from shosondemand where id IN (select id  from tmp_shoe_id);


Good Luck,
Kent'
0
Sudaraka WijesingheWeb Application ProgrammerCommented:
If you need to use the = (equal sign) you need to make sure the second query only returns a single value.
0
dqmqCommented:
I like this, but admit it's equivalent to Dan's query.  The advantage is that it allows you to select fields from the tmp_shoe table if you like:

Select s.* from shosondemand s inner join tmp_shoe_id t on t.id = s.id
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.