Search for more than one value in the same column?

Asked

Viewed 447 times

1

The table has the fields (id_exam, id_patient, data_exam, resultated) and has exams from 2010 to today. I would like to bring you the records of patients who had their exams in 2011, 2012 and 2015 for example. It has to bring the records in those years, that is, it was made in 2011, 2012 and 2015. It is possible to bring the records?

3 answers

0

It’s possible to do something like this:

SELECT * FROM
    nome_tabela 
WHERE EXTRACT(YEAR FROM data_exame) = 2015
     AND EXTRACT(YEAR FROM data_exame) = 2016;

0

Make sure it fits you:

2 years

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

3 years old

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 one 'OR' and not a 'AND'.

-1

You can use OR as has been said but can also do so with AND:

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

or you can use the BETWEEN:

WHERE YEAR(data_exame) BETWEEN 2015 AND 2016

Browser other questions tagged

You are not signed in. Login or sign up in order to post.