0
I have the following tables I created.
CREATE TABLE produto (
codigo INT UNSIGNED NOT NULL AUTO_INCREMENT,
nome VARCHAR(128) NOT NULL,
url VARCHAR(255) NOT NULL,
qde_min SMALLINT UNSIGNED NOT NULL,
prazo_entrega TINYINT UNSIGNED NOT NULL,
descricao VARCHAR(1000) DEFAULT NULL,
status TINYINT(1) DEFAULT '0',
PRIMARY KEY (codigo)
);
CREATE TABLE produto_preco (
valor DOUBLE(9, 2) NOT NULL,
cod_produto INT UNSIGNED NOT NULL,
data DATETIME NOT NULL,
FOREIGN KEY (cod_produto) REFERENCES produto (codigo)
);
I need that when running the VIEW, return all products with their last value. That is the value that has the latest product date.
When I consult my VIEW, the data is returned as follows:
SELECT * FROM view_site_products;
VIEW SQL:
CREATE OR REPLACE VIEW view_site_produtos AS
SELECT p.codigo, p.nome, p.url, pp.valor FROM produto p
LEFT JOIN produto_preco pp ON p.codigo = pp.cod_produto
GROUP BY p.codigo;
I’ve tried with ORDER BY, and I haven’t been able to!
Note that the product Orange is worth 20
SELECT * FROM product_preco;
Being that the correct value is 18, as it has the most recent date!
Any of you have a suggestion, or a solution to how I can make this work?
I’m not sure I understand, but when you tried to order it, I was like,
order by data desc
?– rLinhares
I tried ASC and DESC, and it didn’t help!
– André Felipe