Home > Database > Mysql Tutorial > mysql之exists子查询_MySQL

mysql之exists子查询_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:36:25
Original
1130 people have browsed it

bitsCN.com

mysql之exists子查询

 

子查询可以分为:from where 和 exists子查询

分类表:

 

[sql] 

mysql> select * from category;  

+----+---------+  

| id | c_name  |  

+----+---------+  

|  1 | ios     |  

|  2 | android |  

|  3 | sb      |  

+----+---------+  

3 rows in set  

 

商品表:  

[sql] 

mysql> select * from goods;  

+----+---------+--------+-------+-----+  

| id | name    | cat_id | price | num |  

+----+---------+--------+-------+-----+  

|  1 | 苹果    |      1 |  4999 |   2 |  

|  2 | nexus4  |      2 |  1999 |   3 |  

|  4 | 荣耀2   |      2 |  1888 |   5 |  

|  6 | 三星    |      2 |  3000 |   2 |  

+----+---------+--------+-------+-----+  

6 rows in se  

要求:只找出分类下有商品的分类

 

[sql] 

mysql> select * from category c where exists (select * from goods where cat_id=c.id);  

+----+---------+  

| id | c_name  |  

+----+---------+  

|  1 | ios     |  

|  2 | android |  

+----+---------+  

2 rows in set  

 

bitsCN.com
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template