Saturday, August 31, 2013

MySQL selecting data from 2 tables

MySQL selecting data from 2 tables

I have 2 mysql tables, members and team_members.
members table:
member_id
name
team_members table:
team_id
member_id
I want to select the data from the members table that do not belong to any
team (do not exist in team_members table)
SELECT *
FROM members
INNER JOIN team_members
ON members.member_id = team_members.member_id
The problem is that the query is doing precisely the opposite i need. It
is selecting the data from the members that already have a team. I also
tried with '!=' but that gives me all fields duplicated, but does not
duplicate the members that belong to a team.

No comments:

Post a Comment