How to find data with the same name

Source: Internet
Author: User
How can I find data with the same name? Table Aid & nbsp; name & nbsp; kemu1 & nbsp; & nbsp; Zhang Long & nbsp; Composition 2 & nbsp; & how does nb find data with the same name?
Table
Id name kemu
1 Zhang Long's composition
2 Zhang Long's mathematics
3 Li Si's composition
5. Wang Wu's composition
6 Zhao Hu's mathematics
7. Zhao Hu eloquence
8. Zhao Hu

How can I use SQL statements to find out James and Zhao Hu?

After clicking the search above, it is displayed:
1 Zhang Long
2 Zhao Hu
------ Solution --------------------
Drop table;

Create table (
Id int,
Name varchar (10 ),
Kemu1 varchar (10)
) Charset = gbk;

Set names gbk;

Insert into A values
(1, 'Zhang long', 'Abacus calculation '),
(2, 'Zhang long', 'eloquence '),
(3, 'Zhao Hu', 'Abacus calculation '),
(4, 'Zhao Hu', 'write '),
(5, 'Dynasty ', 'mat '),
(6, 'Dynasty ', 'mat '),
(7, 'mahan', 'pause ');

Select distinct a. name
From,
(Select name, group_concat (kemu1 order by kemu1) as klist from A group by name HAVING count (DISTINCT kemu1)> 1) B
Where find_in_set (A. kemu1, B. klist)
Name
Zhang Long
Zhao Hu

------ Solution --------------------

SELECT name FROM t_xuanke
WHERE id in( SELECT id FROM t_xuanke GROUP BY name,kemu1 HAVING count(*)<=1 )
GROUP BY `name`
HAVING COUNT(*)>1

1. remove records with the same name and same Subject 1
2. find records with multiple names

Lz, your table was originally intended to store students' course selections. it is a good design to use "build a pair of values". why are there so many additional subjects? A lot of complicated and low-efficiency SQL statements begin with an unreasonable table design!

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.