Pick up the value opened

Asked

Viewed 36 times

0

This is my table, I want to get the value abertoCaixa of the greatest idCaixa.

  CREATE TABLE tblcaixa 
  ( 
     idcaixa            INT NOT NULL PRIMARY KEY auto_increment, 
     aberturacaixa      DOUBLE(200, 2), 
     abertocaixa        INT, 
     totalcaixa         DOUBLE (200, 2), 
     hrsaberturacaixa   DATETIME, 
     hrsfechamentocaixa DATETIME 
  );
  • What’s your question? What have you tried so far? I suppose your question is about Mysql and not about Mysql Workbench.

  • select max(idCaixa) from tblCaixa; this code takes the largest idCaixa, but I want to take the opened valueCaixa from the highest idCaixa

  • 1

    I suggest [Edit] the question and add as much information as possible

2 answers

3

The query below may be a possibility to return what you need.

SELECT abertoCaixa FROM tblCaixa WHERE idCaixa = (SELECT MAX(idCaixa) FROM tblCaixa);
  • 1

    Exactly that! Thank you very much!

0

You don’t need two SELECT to do so, simply order in descending order by idcaixa and fetch the first record:

SELECT abertocaixa
FROM tblcaixa
ORDER BY idcaixa DESC
LIMIT 1

See working on DB Fiddle

Browser other questions tagged

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