Where subquery failed,

Source: Internet
Author: User
Where subquery failed. This post was last edited by u010572351 at 17:14:25



Select goods_id, cat_id, goods_name from goods where goods_id =
(Select max (goods_id) from goods );

The statement is correct! However:

Query the last added item information in the item table (maximum goods_id ),
I understand the concept, but the condition value after the where condition is a select statement. although he returns a maximum value, it is a select statement and should be a result set, it's not an int. how can I compare it with goods_id? Stopped.



Reply to discussion (solution)

If a single result is in the result set, the = symbol can be used.
If there are multiple results, they are often written in. Generally, they are based on their own needs. in this way, we can basically determine what the subquery results are (single or multiple), and then select an appropriate operator.

In short, this is acceptable, because the result set has only one result.

If a single result is in the result set, the = symbol can be used.
If there are multiple results, they are often written in. Generally, they are based on their own needs. in this way, we can basically determine what the subquery results are (single or multiple), and then select an appropriate operator.

In short, this is acceptable, because the result set has only one result.

Yes, thank you!

The subquery result can be used as a condition for another query. when you have only one query result, you can use =

Yes, select max (goods_id) from goods) returns the record set
Goods_id = (select max (goods_id) from goods)
Goods_id in is also a record set (because each row has one)

Of course we can compare it.

Well, I will also write this query.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.