X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 71BAA475E40 for ; Mon, 3 Mar 2003 12:20:08 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 56096-01 for ; Mon, 3 Mar 2003 12:20:05 -0500 (EST) Received: from shield.pirmabanka.lv (unknown [195.114.57.4]) by postgresql.org (Postfix) with ESMTP id 5F9B2475D91 for ; Mon, 3 Mar 2003 12:18:02 -0500 (EST) Received: from wall2.pirmabanka.lv (wall2-pub.pirmabanka.lv [195.114.57.14]) by shield.pirmabanka.lv (8.9.3/8.9.3) with SMTP id TAA19872 for ; Mon, 3 Mar 2003 19:18:06 +0200 Received: from share.pirmabanka.lv ([10.0.0.10]) by wall2.pirmabanka.lv; Mon, 03 Mar 2003 19:18:05 +0200 (EET) Received: from pc311x1.pirmabanka.lv (localhost.localdomain [127.0.0.1]) by pirmabanka.lv (8.11.6/8.11.6) with SMTP id h23HI5o25836 for ; Mon, 3 Mar 2003 19:18:05 +0200 Received: (qmail 16181 invoked by uid 100); 3 Mar 2003 17:18:16 -0000 Date: Mon, 3 Mar 2003 19:18:16 +0200 From: "Victor Yegorov" To: pgsql-sql@postgresql.org Subject: Re: complex query Message-ID: <20030303171816.GH9377@pirmabanka.lv> Mail-Followup-To: pgsql-sql@postgresql.org References: <1046689145.1223.7.camel@MattGerg> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="J/zg8ciPNcraoWb6" Content-Disposition: inline In-Reply-To: <1046689145.1223.7.camel@MattGerg> User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/79 X-Sequence-Number: 12119 --J/zg8ciPNcraoWb6 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Matt Gerginski [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. >=20 > Here are the tables: >=20 > 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 >=20 > select username, mailing_list from options; > username | mailing_list > ---------------+-------------- > payday | t > god | t > fake | t > mattgerg | t >=20 >=20 > I want to write a query that will return the emails of only the users > payday, god, fake, and mattgerg. >=20 > Is this at all possible? I am new to sql, and I am having trouble. >=20 select u.username, u.email from users as u, options as o where u.username = =3D o.username and o.mailing_list =3D true; You'd better read some book on SQL. --=20 Victor Yegorov --J/zg8ciPNcraoWb6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+Y45Y2RKGLEykUDYRAj07AKCNRTYS2hEXGDjJBWZ+x+4Rs0ZlLACgk7WE ecXOKm93Zs2+2rGTVN50gGY= =pUsu -----END PGP SIGNATURE----- --J/zg8ciPNcraoWb6--