Pull information last information that will use to make comparison

1

I have a question in SQL, what I want is that the code pulls the last information from this column and compares with a label on my site, but I do not know if the Last Insert Id is better or correct to use. >

SELECT Km_Atual FROM Rota WHERE Km_Atual as LAST_INSERT_ID(Km_Atual)
    
asked by anonymous 12.06.2017 / 20:56

2 answers

1

The problem with using LAST_INSERT_ID() is that it only returns the value of AUTO_INCREMENT of your table, in your case the id , but if you still want to use it, it would look like this:

SELECT LAST_INSERT_ID() FROM Rota;

If you still want Km_Atual , you can use MAX() with id .

SELECT Km_Atual FROM Rota WHERE id=MAX(id); 

And to make the comparison:

if(Km_Atual == label1.Text) //Onde Km_Atual é a string em que você armazenou o que o select retornou e label1 é o nome da sua label.
    
13.06.2017 / 00:16
1

To pull the last line you can do this:

SELECT Km_Atual FROM Rota ORDER BY Id DESC LIMIT 1;
    
12.06.2017 / 23:02