|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|