NYCPHP Meetup

NYPHP.org

[nycphp-talk] Multiple query from out put

Daniel Convissor danielc at analysisandsolutions.com
Tue Sep 20 09:56:27 EDT 2005


Hi Paul:

On Mon, Sep 19, 2005 at 06:06:05PM -0400, thegeek wrote:

> I have a script that searches a table within the database and 
> returns multiple enteries(zip codes) in that table.  I would then like to 
> take each one of zipcodes and search another table for store addresses.

-- create some sample talbes and data
create table zips (zip char(1), cond char(1));
insert into zips values ('1', 'a');
insert into zips values ('2', 'a');
insert into zips values ('3', 'b');

create table stores (zip char(1), name char(1));
insert into stores values ('1', 'm');
insert into stores values ('2', 'n');
insert into stores values ('2', 'o');
insert into stores values ('3', 'p');

-- show how to make a nice joining query
select zips.zip, name
from zips
join stores using (zip)
where cond = 'a';

-- remove these sample tables
drop table zips;
drop table stores;

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list