Jump to content
xisto Community
leiaah

Subquery In Mysql

Recommended Posts

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

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

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

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

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
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

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

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 link

There 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.