Home  >  Article  >  Database  >  mysql subquery example analysis

mysql subquery example analysis

PHPz
PHPzforward
2023-05-28 10:07:05946browse

Subquery can be understood as a query nested in other statements, so we have different usage methods for different query results.

1. The subquery is a single-value result, so you can use comparison operators such as = and > on it.

# 查询价格最高的商品信息
select * from t_product where price = (select max(price) from t_product)

2. The subquery is a multi-valued result, so you can use [not]in (subquery result) or >all (subquery result) for it.

# 查询价格最高的商品信息
SELECT * FROM t_product WHERE price >=ALL(SELECT price FROM t_product)

The above is the detailed content of mysql subquery example analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete