Hey guys im trying to do a query on our database, the pieces of information i need are in 2 tables within my database.
table 1= customers
- information i need from this table:
table 2= orders
both tables contain more fields than just the above stated.
I'm trying to find out which customer has made the most orders, my code below works fine on a small database:
SELECT customers_firstname, customers_lastname, COUNT(orders_id) AS Number FROM customers LEFT JOIN orders AS o USING (customers_id) GROUP BY (o.customers_id) ORDER BY Number DESC LIMIT 5;
However there's over 35000 people in the database so the query always crashes.
the problem as i see it is with the LEFT JOIN, because as far as i understand it the left join will basically merge the two tables with all fields.
im still a rather new to mysql databases can anyone help?