leiaah 0 Report post Posted January 29, 2006 Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows how. Can anyone help? Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database from MSAccess to MySQL. Help! Thanks. Share this post Link to post Share on other sites
Tyssen 0 Report post Posted January 29, 2006 This example from the MySQL site: SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2); Share this post Link to post Share on other sites
leiaah 0 Report post Posted January 30, 2006 This example from the MySQL site: SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2); 225154[/snapback] Thanks! I needed this for a project. Share this post Link to post Share on other sites
leiaah 0 Report post Posted January 31, 2006 This example from the MySQL site: SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2); 225154[/snapback] I've tried what you've suggested but still nothing. I've tried these statements: select * from item where id='select max(id) from users';select * from item where id=('select max(id) from users');and I get an error like:Unknown column 'id' in where 'clause'Have you tried it and had it worked? Thanks. Share this post Link to post Share on other sites
beeseven 0 Report post Posted January 31, 2006 In the ones you say you tried, you have single quotes around the subquery, but leiaah's code didn't. That could be the problem, because it's probably treating it that way as a string instead of a query. Share this post Link to post Share on other sites
iGuest 3 Report post Posted August 13, 2008 sub query in sql Subquery In Mysql Helo guys I have a subquery and I really need this code.. But the problem is the system says syntax error.. Is there anyway to make it correct? This is my code: Select sales.Clientcode,sales.Name,sum(sales.Grossamt)as totalsales From (select client.Clientcode,client.Name,points1.Grossamt From client inner join points1 On client.Clientcode=points1.To) sales Group by sales.To -reply by VicSlayer Share this post Link to post Share on other sites
iGuest 3 Report post Posted October 15, 2009 select query is the sub query of insert query Subquery In Mysql"INSERT tb_customers ( `prod_id`, `prod_serial`, `brand_id` , `model_id`, `capacity_id`, `certificate_no`, `description`, `class`, `accuracy`, `added_date`, `price`, `maximum`, `minimum`, `bill_no` )VALUES( SELECT `prod_id`, `prod_serial`, `brand_id` , `model_id`, `capacity_id`, `certificate_no`, `description`, `class`, `accuracy`, `added_date`, `price`, `maximum`, `minimum`FROM tb_productsWHERE `prod_id`='$serialid')"; is it correct ? please reply me soon -reply by venkatesh Share this post Link to post Share on other sites
Raidation 0 Report post Posted October 25, 2009 No it's not "INSERT INTO tb_customers ( `prod_id`, `prod_serial`, `brand_id` , `model_id`, `capacity_id`, `certificate_no`, `description`, `class`, `accuracy`, `added_date`, `price`, `maximum`, `minimum`, `bill_no` )VALUES(SELECT `prod_id`, `prod_serial`, `brand_id` , `model_id`, `capacity_id`, `certificate_no`, `description`, `class`, `accuracy`, `added_date`, `price`, `maximum`, `minimum`FROM tb_productsWHERE `prod_id`='$serialid')"; As you can see, I added an INTO Share this post Link to post Share on other sites
magiccode9 0 Report post Posted October 28, 2009 If you are working with a project that use mysql.I would suggest that you download a copy of mysql manual and store in your hard drive for future reference.http://forums.xisto.com/no_longer_exists/click the documentation linkThere are many file format you can choose from.Assume that you are on linux.PDF file should be the one you need to get.Enjoy scripting and database. Share this post Link to post Share on other sites