Multiple Entry of Groceries

 

Write an SQL query to find the multiple entries of all the groceries from the table.



Input :-

Groceries table :-
ID is the Primary Key column for the Groceries table.

ID

Fruits

1

Apple

2

Orange

3

Apple

4

Mango



Output :-

Fruits

Apple



Query :-
select Fruits 
from Groceries
group by Fruits
having count(Fruits)>1;

Explanation : - 

This SQL query retrieves data from a table named "Groceries" and filters the data to only show rows where the same fruit appears more than once. The query does this by using the GROUP BY clause to group all the rows with the same fruit together, and then uses the HAVING clause to filter out any groups with a count of more than 1.

So essentially, this query is looking for fruits that have duplicates in the "Groceries" table. It will return a list of the duplicate fruits.






No comments

darkmode