1
Hello I am trying to see the previous record in relation to the current record. I am using the following Cód.
SELECT * FROM Tabela WHERE compoid <"Contraband" ORDER BY compoid DESC LIMIT 1;
But it is returning the blank table What’s wrong? How can I search for the previous record using select in mysql
What should be the value of the previous record in compoid? Tested with other values? Great chance the problem is in the data.
– Bacco
From what I understand your field
compoid
would be an integer numeric, usually auto increment, you’re comparing it to a string?compoid < "Contraband"
– KaduAmaral
@Kaduamaral Could you please send a code with this <"contraband" string? Please
– Fabrício Mendes
@Bacco my doubts would be to take the value of the previous record in relation to the last position of records. Therefore the limit 1
– Fabrício Mendes
This part is clear to me, what I asked is what would be the value of the previous record. I also asked if you tested with other values. You are ordering by Compoid for want alphabetical order?
– Bacco
@Bacco Yes ordering by Compoid, but next there is no way I know which is last record, since I am running all this from the client side via queyri. Or has?
– Fabrício Mendes
If I were you, I’d select them all first, just in order, to see what comes back. Then I would put the limit back, because the problem may be, as I said, in the data you are testing, and not in the query. Your query seems right, but since you didn’t put the table structure in the question, it may not and it may be that.
– Bacco
@Fabríciosimonealanamendes for me to send you a code, I need to know the modeling of your table. Edit your question informing the modeling of the table and some values, so we can help you...
– KaduAmaral