You forgot to include the meaningful link on the foreign key in your where-clause:
db.sales.mail = db.customers.mail
Also, use brackets to group your conditions together. Something like cond1 OR cond2 AND cond3
will probably not work as expected, so for example you could write this as (cond1 OR cond2) AND cond3
.
So something like this should work:
SELECT db.customers.first_name,
db.customers.last_name,
db.customers.mail,
db.sales.event_year,
db.sales.ticket_type,
db.sales.event_name
FROM db.sales, db.customers
WHERE db.sales.mail = db.customer.mail
AND (db.sales.ticket_type = "ticket1"
OR db.sales.ticket_type = "ticket2"
OR db.sales.ticket_type = "ticket3")
AND (db.sales.event_year=2009
OR db.sales.event_year=2010)
While the above should work, it's better to write it like this (mostly for readability):
SELECT c.first_name,
c.last_name,
c.mail,
s.event_year,
s.ticket_type,
s.event_name
FROM db.sales s
INNER JOIN db.customer c ON s.mail = c.mail
WHERE s.ticket_type IN ('ticket1','ticket2','ticket3')
AND s.event_year IN (2009,2010);
Note: I simply removed the final GROUP BY
in your query, since I don't know what you're trying to accomplish with that. If you use GROUP BY
, it should be on at least all selected columns that are not aggregate functions (like SUM
, COUNT
etc.)