Re: complex query - Mailing list pgsql-sql

From Victor Yegorov
Subject Re: complex query
Date
Msg-id 20030303171816.GH9377@pirmabanka.lv
Whole thread Raw
In response to complex query  (Matt Gerginski <mattgerg@users.sourceforge.net>)
List pgsql-sql
* Matt Gerginski <mattgerg@users.sourceforge.net> [03.03.2003 19:11]:
> I have two tables, users and options.  The common element between the
> tables is "username".  I want to select the "email" from "user" but only
> if the "mailing_list" option is set to true in the "options" table.
>
> Here are the tables:
>
> select username, email from users;
>    username    |             email
> ---------------+--------------------------------
>  joe           | joe@yahoo.com
>  heidi         | heidi@localhost
>  payday        | brant@localhost
>  fake          | fake@localhost
>  mattgerg      | mattgerg@users.sourceforge.net
>  god           | god@heaven.org
>
> select username, mailing_list from options;
>    username    | mailing_list
> ---------------+--------------
>  payday        | t
>  god           | t
>  fake          | t
>  mattgerg      | t
>
>
> I want to write a query that will return the emails of only the users
> payday, god, fake, and mattgerg.
>
> Is this at all possible?  I am new to sql, and I am having trouble.
>

select u.username, u.email from users as u, options as o where u.username =
o.username and o.mailing_list = true;


You'd better read some book on SQL.

--

Victor Yegorov

pgsql-sql by date:

Previous
From: saintxplo@yahoo.com.ar (Saint X)
Date:
Subject: Insert multiple Rows
Next
From: "Victor Yegorov"
Date:
Subject: Re: Insert multiple Rows