embsupafly Posted March 30, 2006 Share Posted March 30, 2006 Trying to run the following MySQL query/subquery:SELECT products_id FROM products_attributes WHERE products_id = (SELECT products_id FROM products WHERE products_model = 'V100');I am doing this in phpMyAdmin and I am getting back a syntax error.I am running MySQL version 4.0.25, and thought I heard something a while back that subqueries were not supported until 4.1, but then again, I am not sure, but I don't want to rack my brain out if this isn't going to work wity my version of MySQL.Should this work in pre 4.1 MySQL? Do I have the wrong syntax? Is there an alternative way to do this.What I am trying to do with the query is select all products_id from the products_attributes table that match products_ids that are in the products table that correspond to a certain products_model. Quote Link to comment https://forums.phpfreaks.com/topic/6148-mysql-subquery-helpalternative/ Share on other sites More sharing options...
fenway Posted March 30, 2006 Share Posted March 30, 2006 You're correct -- no subqueries until v4.1.Luckily, in your case, you can rewrite this a JOIN -- which is usually better to do anyway, if possible (UNTESTED):[code]SELECT p.products_id FROM products AS p LEFT JOIN products_attributes AS pa ON ( p.products_id = pa.products_id ) WHERE p.products_model = 'V100';[/code]Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/6148-mysql-subquery-helpalternative/#findComment-22226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.