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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested selects in mySQL with PHP?

Status
Not open for further replies.

QuietFire

Programmer
Joined
Feb 25, 2003
Messages
12
Location
US
I can find a longer way around my problem, but when I was doing a lot of asp/MS SQL stuff I sued to do write some pretty specific queries. I tried this through phpMyAdmin and received syntax errors. I guess what I want to know more than anything is, is it possible in php/mysql?

SELECT userpermissions.location_id ,locations.loc_name FROM locations WHERE userpermissions.location_id IN (SELECT userpermissions.userid FROM userpermissions WHERE userpermissions.userid = '4')

like I said, I can get there in a round about way, but it seams something like this should be possible.

Thanks in advance,

Charlie
 
While your question is much better suited for the MySQL forum, since it has nothing to do with php, I will point you to your answer anyway. Subqueries have only become available in MySQL recently. If you have an older version, you need to upgrade. More:

 
Code:
SELECT userpermissions.location_id ,locations.loc_name FROM  locations WHERE userpermissions.location_id IN (SELECT userpermissions.userid FROM userpermissions WHERE userpermissions.userid = '4')

Don't you miss anything in your "FROM"-Part?

Code:
SELECT userpermissions.location_id ,locations.loc_name FROM  locations, [red]userpermissions[/red] WHERE userpermissions.location_id IN (SELECT userpermissions.userid FROM userpermissions WHERE userpermissions.userid = '4')

I thought you must specify all your tables, but I'm not an SQL-guru
 
ORettinger.. I'm a little rusty...[blush]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top