Unix Technical Forum

query problem

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:32 AM
Tarscher
 
Posts: n/a
Default query problem

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:32 AM
Rik Wasmus
 
Posts: n/a
Default Re: query problem

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com