Home > Database > Mysql Tutorial > mysql >查询语句_MySQL

mysql >查询语句_MySQL

WBOY
Release: 2016-06-01 13:35:20
Original
1582 people have browsed it

bitsCN.com

mysql >查询语句

 

* 查询多条不重复记录

  id name

  1 a

  2 b

  3 c

  4 c

  5 b

select id, name from s1 group by name

1 a

2 b

3 c

5 b

 

* 查询重复记录最多的记录

SELECT keyword, count( * ) AS count  

FROM article_keyword  

GROUP BY keyword  

ORDER BY count DESC  

LIMIT 20 

 

* 查询重复记录和重复次数

select user_name,count(*) as count from user_table group by user_name having count>1;

 

 * 多联查询

s1表

id name

3    a

 

s2表

id s1_id age 

1   2     12

2   3     23

 

SELECT * FROM `s2` WHERE `s1_id` = (SELECT id FROM `s1` WHERE `name` = 'a');

 

结果 

2   3     23

 

bitsCN.com
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template