What should I do if the where subquery has expired?

Source: Internet
Author: User
Where subquery failed. This post was last edited by u010572351 from 2013-06-2817: 14: 25 & nbsp; select & nbsp; goods_id, cat_id, & nbsp; goods_name & nbsp; from & nbsp; goods & nbsp; where & nbsp; goods_id & nbsp; (select 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, he is a select statement. it should be a result set rather than an int. how can he compare it with goods_id?Stopped.


Share:


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

------ Solution --------------------
The subquery result can be used as a condition for another query. when you have only one query result, you can use =
------ Solution --------------------
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.

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.