I have two databases: one contains the users:
persons
id
name
course
the other one contains the
voters
id
personID
type
An entry to the voters table gets added when the user voted (type describes different topics a user can vote on)
I want to get all users for example where persons.course = '1' AND voters.type = '2' and have the output contain the following columns: id, name, hasVoted (where hasVoted returns true if the personID can be found in the voters table)
A left join may be what your looking for.
http://dev.mysql.com/doc/refman/5.0/en/join.html
The left join will include all the matching rows from the left side of the join, and any matching pieces from the right side of the join. Any rows from the left side without a matching right side will be have the right side columns values of null.
As for the ‘IS NOT NULL’ or ‘IS NULL’ is used because ‘X = NULL’ doesn’t behave as it appears.
More details about working with nulls:
http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html