php - getting all the records in the table
348
i wanted to retrieve all the records whose "amount" is greater than or equal to 1500. The problem is even if the "amount" is less than 1500 it will be also displayed in the page.
customers table
id name
1 sample
2 sample2
3 sample3
payments table
p_id amount id(foreign key)
1 800 2
2 800 2
3 1500 1
4 1200 3
costumer 1 and 2 should be retrieved because the amount>= 1500.
Thank you, Mick :)
Answer
Solution:
This requires to join the tables.
GROUP BY
is used since one of the columns is being aggregated usingSUM()
and theHAVING
clause is used to filter the result of aggregation.