I don't think Sub queries like the = and != operators as groupid will never
equal the result of a multi row subquery, but it can be IN a list of
results. Just to check, you are using 4.1+ right? I think this alteration
would work:
============
SELECT group_id,name,'SELECTED' FROM groups WHERE group_id IN (SELECT
group_id FROM user_groups WHERE userid= 1) UNION
Select group_id,name,' ' FROM groups WHERE group_id NOT IN (SELECT group_id
FROM user_groups WHERE userid= 1) ORDER by group_id
=========
That being said, I think you can do it without Subqueries with this query:
========================
SELECT
group_id,
name,
IF(1=userid,'SELECTED',' ')
FROM groups
ORDER BY group_id
========================
Chris
-----Original Message-----
From: Geeta Rajaraman [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 05, 2003 7:03 AM
To: [EMAIL PROTECTED]
Subject: MySQL sub-query error.
Good Morning everyone:
I need help figuring out what is wrong with this query. I have tried to
use the LEFT JOIN, but it doesn't solve the purpose.
This is what I am trying to run:
============
SELECT group_id,name,'SELECTED' FROM groups WHERE group_id = (SELECT
group_id FROM user_groups WHERE userid= 1) UNION
Select group_id,name,' ' FROM groups WHERE group_id != (SELECT group_id
FROM user_groups WHERE userid= 1) ORDER by group_id
=========
I get this error:
You have an error in your SQL syntax near 'SELECT group_id FROM
user_groups WHERE userid= 1) union select group_id,name
I have run the sub queries individually, and they work.
Can anyone help ? I have tried various combinations..but each time I get
the same error.
Thanks!
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]