MySQL Forums
Forum List  »  Newbie

Execute search last record with condition " IF "
Posted by: Gerson Roberto da Silva Gerson
Date: May 01, 2016 10:09AM

Good Morning

I have a doubt, already researched on some topics, but could not solve my problem if someone can help me thank you.

Sorry but a few words are in Portuguese in Brazil.

My problem is as follows:

I have a table like the example below where I have 25 items, this table I use to mount a second table, or with id_relatorio I feed table with id_relacao_atividade, thus the id_relatorio appears "n" times in relacao_atividade table.

So I need to list all the latest relacao_atividade records containing only one id_relatorio iten, 'if and only if' meet the following requirements:



id_status = '1' AND (resp_1 = '1' OR resp_2 = '1' OR resp_3 = '1' OR resp_4 = '1')



That is, I want only the last record of each GROUP BY id_relatorio if and only if it meets the line described above.



small example from my table:

[Id_relacao_atividade] - [id_relatorio] - [id_status] - [resp_1] - [resp_2] - [resp_3] - [resp_4] - [numero_linha]

[1] - [1] - [2] - [1] - [1] - [0] - [0] - [1]

[2] - [1] - [1] - [1] - [1] - [1] - [1] - [2]

[3] - [2] - [3] - [3] - [1] - [0] - [0] - [1]

[4] - [3] - [1] - [3] - [1] - [1] - [1] - [1]

[5] - [3] - [2] - [1] - [1] - [1] - [1] - [2]



For my search is correct only id_relacao_atividade 2 meets my search.

The numero_linha should be the maximum value within the search requirements so I guarantee hte took the last value within the requirements.

Already I tried this:



SELCT MAX (numero_linha) FROM WHERE relacao_atividade id_status = '1' AND (resp_1 = '1' OR resp_2 = '1' OR resp_3 = '1' OR resp_4 = '1') GROUP BY id_relatorio

However it also returns me values ​​that are not the last of each id_relatorio .

So my statement " if and only if " meet my requirements .

Thanks

Options: ReplyQuote


Subject
Written By
Posted
Execute search last record with condition " IF "
May 01, 2016 10:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.