My database has these tables:
- Productos
- Productos_Presentaciones
This is an inventory and I want to know from all the products (productos), which one has more stock. So this is the last thing I could think of:
SELECT MAX(pp.Existencias), p.Nombre as PRODUCTO FROM Productos_Presentaciones pp
full join Productos p on pp.Id_Producto = p.Id_Producto
group by p.Nombre;
And this is the result:
I just need to be shown a single result. In this case, the #9 from the image shown:
PRODUCTO EXISTENCIA
Carne de cangrejo de Boston 123
Which is the product with the most available stock.
CodePudding user response:
You can use Order by clause and limit for getting just one row
SELECT MAX(pp.Existencias) AS pex, p.Nombre as PRODUCTO FROM Productos_Presentaciones pp
FULL JOIN Productos p on pp.Id_Producto = p.Id_Producto
GROUP BY p.Nombre ORDER BY pex DESC LIMIT 1;