2
Answers

How to write down a query for repeted value in sql

Photo of Anjali Khan

Anjali Khan

7y
143
1
Dear frnds I have a table like employee ------------------------- EID. ENAME --_----------------------- 1 A 2. B 3. C 4. A 5. B 6. C 7. A ---------------------------- I want the display like A = 3 B = 2 C = 2 How to do this

Answers (2)

0
Photo of Anjali Khan
NA 738 42.5k 7y
Hi NileshSo my query like this select emp_name, count(emp_name) e from employee group by emp_name order by e desc;
0
Photo of Nilesh Patil
NA 3.4k 7k 7y
Hi,
 
To get a list of values and the number of their appearances:
 
select col_name, count(col_name) c from table
group by col_name
order by c desc;
 
If you want only the most common value:
 
select col_name, count(col_name) c from table
group by col_name
order by c desc
limit 1;