This is a discussion on query problem within the MySQL forums, part of the Database Server Software category; --> Hi all, I have users that have many accounts I want to show all users and the account (if ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all, I have users that have many accounts I want to show all users and the account (if she has one) of a certain type. How can I query all users and if the user has a specific account, the account. If I do WHERE accounts.type = 'type' I only get the users with an account. I also want the users without an account. Someone has an idea how to solve this? Thanks Stijn |
| ||||
| On Sat, 02 Feb 2008 14:52:44 +0100, Tarscher <tarscher@gmail.com> wrote: > Hi all, > > I have users that have many accounts > > I want to show all users and the account (if she has one) of a certain > type. > > How can I query all users and if the user has a specific account, the > account. If I do WHERE accounts.type = 'type' I only get the > users with an account. I also want the users without an account. SELECT users.name, IF(accounts.id IS NULL,0,1) as 'hasSpecificAccount' FROM users LEFT JOIN accounts ON users.id = accounts.user_id AND accounts.type = 'type' -- Rik Wasmus |
| Thread Tools | |
| Display Modes | |
|
|