How to catch the latest releases of an Inner Join

Asked

Viewed 40 times

1

Staff to making a query in 3 tables with Internet, follow the code:

 select 
        itensVenda.idVenda, itensVenda.idProd, itensVenda.qtd,
        produtos.id, produtos.descricao, produtos.foto,
        venda.id, venda.valor
   from produtos 
  INNER JOIN itensVenda ON produtos.id = itensVenda.idProd 
  INNER JOIN venda ON itensVenda.idVenda = venda.id

So far so good is taking everything, what I would like:
i have in itensVenda two equal sale id id in the last release, how can I redeem this release showing me the last idVenda? example: I have two sale id 0009 and wanted to unite them

  • Try... ORDER BY idVenda DESC LIMIT 1

  • I believe that you need to group, you can put in the question an example of the data that returns?

  • I tried this but back only one result being that I have two id sale

  • he returns like this:

  • I’ll post it like I did. select itensVenda.idVenda, itensVenda.idProd, itensVenda.Qtd, products.id, products.Description, products.photo, sale.id, sale.valor from products INNER JOIN itensVenda ON products.id = itensVenda.idProd INNER JOIN sale ON itensVenda.idVenda = sale.id WHERE itensVenda.idVenda = (SELECT MAX(id) FROM sale WHERE id = id) and on the page you call I’ve placed a javascript script redirecting like this: echo 'Location.href="ver_compra_final.php? id=$id"

1 answer

0

I’ll post like I did.

select itensVenda.idVenda, itensVenda.idProd, itensVenda.qtd, produtos.id, produtos.descricao, produtos.foto, venda.id, venda.valor from produtos INNER JOIN itensVenda ON produtos.id = itensVenda.idProd INNER JOIN venda ON itensVenda.idVenda = venda.id WHERE itensVenda.idVenda = (SELECT MAX(id) FROM sale WHERE id = id)

and on the page you call I put a script in javascript redirecting like this:

echo 'Location.href="ver_compra_final.php? id=$id";';

Browser other questions tagged

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