1
I have this table in `Mariadb [accounts]>
SELECT * FROM mercado WHERE nome_mercado LIKE 'extra';
+----+--------------+-------------+-----------+-----------+-------+
| id | nome_mercado | data_compra | produto | descricao | preco |
+----+--------------+-------------+-----------+-----------+-------+
| 1 | Extra | 2017-07-12 | Coca Cola | Coca | 3.00 |
| 2 | Extra | 2017-07-12 | Sucos | Suco | 3.50 |
| 3 | Extra | 2017-07-12 | Frios | Frios | 7.80 |
| 11 | extra | 2017-07-28 | Suco | Teste | 5.90 |
| 12 | extra | 2017-07-28 | Bolacha | | 2.49 |
+----+--------------+-------------+-----------+-----------+-------+`
I would like you to return only the products with the latest dates, that is, only these:
| 11 | extra | 2017-07-28 | Suco | Teste | 5.90 |
| 12 | extra | 2017-07-28 | Bolacha | | 2.49 |
I used this select, but it returns nothing:
Mariadb [accounts]>
SELECT * FROM mercado WHERE nome_mercado LIKE 'extra' =
(SELECT data_compra FROM mercado ORDER BY data_compra DESC LIMIT 1);
Empty set, 5 warnings (0.00 sec)
I would put this Where in the second select? , after the "=" ?
– user54154
@user54154 see edition.
– viana