MySQL query Problem for 2 tables?

Question by Marry Maharani: MySQL query Problem for 2 tables?
I have 2 tables , orders and sold :

Table orders :
id product quantity :
1 bag 10
2 shoes 10
3 cloth 5
4 hat 15

I sold bag 10 pcs , shoes 5 pcs , then inserted data in the table “sold” :
id quantity
1 10
2 5

So I want to make MySQL php script which should show the products which are not sold yet as follows :

id product quantity
2 shoes 5
3 cloth 5
4 hat 15

Thank you
Thank you all,

By the way the query made by “Eric B” works fine for small database, but with large database it works slow , any more efficient trick?

Thank you

Best answer:

Answer by David Bandel
I’m assuming your id field in the “sold” table refers to the id of the item in the “orders” table. If not you need to add an id_stock or id_orders field to your “sold” table.

The script is not difficult.

Something like

Select * from sold where quantity > 0

Know better? Leave your own answer in the comments!

Get the book now