Search for more than one value in the same column? [closed]

1

The table has the fields (query_id, patient_id, data_exame, result) and has exams from 2010 to today. I would like to bring the records of the patients who took exams in 2011, 2012 and 2015 for example. It has to bring the records in those years, that is, it was done in 2011,2012 and 2015. Is it possible to bring the records?

    
asked by anonymous 19.04.2016 / 21:52

3 answers

0

Check if this caters to you:

2 years

SELECT id, data_exame, resultado FROM Minha_tabela where YEAR(data_exame) = 2015 OR YEAR(data_exame) = 2016;

3 years

SELECT id, data_exame, resultado FROM Minha_tabela where YEAR(data_exame) = 2014 OR YEAR(data_exame) = 2015 OR YEAR(data_exame) = 2016;

For each year you add a ' OR ' and not a ' AND '.

    
20.04.2016 / 03:22
0

You can do something like this:

SELECT * FROM
    nome_tabela 
WHERE EXTRACT(YEAR FROM data_exame) = 2015
     AND EXTRACT(YEAR FROM data_exame) = 2016;
    
19.04.2016 / 22:48
-1

You can use OR as you have said but you can also do this with AND :

WHERE YEAR(data_exame) >= 2015 AND YEAR(data_exame) <= 2016

or you can use BETWEEN :

WHERE YEAR(data_exame) BETWEEN 2015 AND 2016
    
21.04.2016 / 13:22