A
A
Alex May2013-09-16 20:26:19
PHP
Alex May, 2013-09-16 20:26:19

Help writing SQL query

Please, help me write a SQL query or poke your nose - which operators to use
Platform: MySQL
The task is to display unique values, 1 at a time.
I will try to explain in more detail, using the example of a table and the desired result

| name | class | state
+-----------------+----------------+
| apple | 1 | true
+-----------------+----------------
| big apple | 1 | false
+-----------------+----------------
| potatoes | 2 | false
+-----------------+----------------
| rotten potatoes | 2 | true
+-----------------+----------------
| cherry | 5 | false
+-----------------+----------------
| plum | 7 | true
+-----------------+----------------


As a result, I want to get a list of unique class values,
that is
(SELECT * FROM table WHERE (I don’t know what here) AND state=TRUE)

result
class: 1,2,7

Answer the question

In order to leave comments, you need to log in

4 answer(s)
H
HiltoN, 2013-09-16
@alexmay

select distinct class from table where state='true'

P
Petrusha Ukropov, 2013-09-16
@artishok

SELECT * FROM table WHERE state=TRUE GROUP BY class

M
Mike Grigorieff, 2013-09-16
@Grigorieff

use

SELECT DISTINCT {имя_столбца_по которому_необходимо_выводить_уникальные_значения} FROM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question