Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - get list of different values from column

Tags:

sql

php

mysql

I have table in MySql where I have column type

in this column type are different types

each row in table have type,

how to get list of those values ( not repeating = DISTINCT) ?

example:

id    name    type
-------------------
1     apple   fruit
2     onion   vegetable
3     banana  fruit

List:

fruit
vegetable

Idea:

SELECT `type` FROM `food` WHERE ...
like image 517
Ing. Michal Hudak Avatar asked Dec 26 '22 07:12

Ing. Michal Hudak


2 Answers

In order to get distinct Data You Use DISTINCT

SELECT DISTINCT TYPE FROM FOOD

like image 98
Blood-HaZaRd Avatar answered Jan 04 '23 23:01

Blood-HaZaRd


You need to use having clause.

  SELECT type FROM food GROUP BY type;
like image 39
Karthik Avatar answered Jan 04 '23 23:01

Karthik