i made a website where customers can rent a maschine for a specified dates.
i use PHP and MYSQL. here is an image that shows my tables and the desired relations.
i need to output a bill. the bill should contain the customers data, the maschines he rented and the dates he selected. the customer can rent multiple maschines and each maschine can be rented for multiple dates that can be non-consecutive.
how do i make a query that returns all the data i need for the bill?
Asked
Active
Viewed 118 times
-1
-
Google how to write a MySQL query? – dfundako Apr 25 '17 at 14:17
1 Answers
0
Your questions is about SQL sentences, no matter if you're using php.
A query as follow will work:
SELECT a.firstname, b.machine, d.from, d.to FROM rents as a, maschines as b, renInfo as c, rentDates as d WHERE c.rid=a.id AND c.mid=b.id AND c.id=d.riid ORDER BY a.firstname, b.machine, d.from, d.to

LlaveLuis
- 88
- 2
- 5
-
Yay this works. had to change it a bit because you made typos (because i made a typo in the first place on my table name) changed it and now it works. thank you. – core36 Apr 25 '17 at 14:42
-
-
Ok, then, this links would be useful: http://stackoverflow.com/questions/6891422/which-is-better-implicit-or-explicit-join , http://stackoverflow.com/questions/5654278/sql-join-is-there-a-difference-between-using-on-or-where – LlaveLuis Apr 25 '17 at 15:58