Hi.
I have a query that looks like this:
SELECT user_id, user_given_name s, user_surname, user_cast FROM users WHERE
user_id NOT IN (SELECT user_id FROM linkage WHERE group_id=1)
ORDER BY users.user_surn ame
What this does is return the users who are not in group 1. linkage
contains user_id, group_id pairs of users who are in what groups. What I
would like to do is write this not using subselects, as they are not
supported in older mysql versions.
So, is it possible to write a query (1 query) using mysql 3.x or 4.0 SQL
that will return the users that don't exist in a specific group when you
have the following table structure (simplified for this example):
users:
user_id
linkage:
user_id, group_id
Users can exists in several groups, that is why I use the linkage table,
otherwise it could be done in an easier way. I tried to experiment using
some joins but I'm stuck. Is subselects the only way? Writing 2 queries is
possible, of course, but I'd rather have it all in one.
Thanks in advance.
--
Mattias Nordstrom
I have a query that looks like this:
SELECT user_id, user_given_name s, user_surname, user_cast FROM users WHERE
user_id NOT IN (SELECT user_id FROM linkage WHERE group_id=1)
ORDER BY users.user_surn ame
What this does is return the users who are not in group 1. linkage
contains user_id, group_id pairs of users who are in what groups. What I
would like to do is write this not using subselects, as they are not
supported in older mysql versions.
So, is it possible to write a query (1 query) using mysql 3.x or 4.0 SQL
that will return the users that don't exist in a specific group when you
have the following table structure (simplified for this example):
users:
user_id
linkage:
user_id, group_id
Users can exists in several groups, that is why I use the linkage table,
otherwise it could be done in an easier way. I tried to experiment using
some joins but I'm stuck. Is subselects the only way? Writing 2 queries is
possible, of course, but I'd rather have it all in one.
Thanks in advance.
--
Mattias Nordstrom
Comment