views:

68

answers:

1

Hey,

I have a table in my SQL in the following structure called actions:

+----+--------+------+---------+
| id | action | type | user_id |
+----+--------+------+---------+
|  1 |      5 |    4 |       1 | 
|  2 |      6 |    4 |       1 | 
|  3 |      5 |    4 |       2 | 
|  4 |      0 |    0 |       2 | 
|  5 |      0 |    1 |       2 | 
+----+--------+------+---------+

and I have the users table like so:

+----+------------+----------------------------------+----------+
| id | fullname   | password                         | username |
+----+------------+----------------------------------+----------+
|  1 | Admin User | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | admin    | 
|  2 | Arthur     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | arthur   | 
|  3 | john       | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | john     | 
+----+------------+----------------------------------+----------+

I want to select all the actions from the action table except for the admins actions, I have tried doing:

SELECT * FROM actions WHERE user_id != 1;

But this does not work in some instances as the admin user_id is not always 1.

How would I go about selecting all the actions except the admin actions, I have tried messing around with JOINS but can not figure it out.

Hope you know what I mean.

Cheers

Eef

+2  A: 
SELECT * FROM actions inner join users
on actions.user_id = users.id 
WHERE users.username != "admin";

assuming all admins have username "admin"

gd047