Basic schema (only relevant fields shown):
customers
id | fname | sname | email
orders
order_id | customer | level | timestamp
I need to select every customer, but along with their personal details I want to join the level of their first order.
SELECT c.fname, c.sname, c.email, o.level
FROM customers c
LEFT JOIN orders o ON c.id = o.customer
..?
Edit
I have tried two solutions so far and they completely kill my entire database. No database requests will complete after running the queries, so I’m wondering if maybe the queries are too large. There are about 10,000 orders and 15,000 customers. Is this expected? I’ve never had these problems before on these tables.
Well, this will work, but is not optimal: