[nycphp-talk] Multiple query from out put
Peter Sawczynec
ps at pswebcode.com
Tue Sep 20 10:45:05 EDT 2005
Have you tried this type of structure:
SELECT s.address AS 'Store Address' FROM stores AS s
WHERE s.zip IN
(SELECT z.zip FROM zipcodes AS z WHERE z.city = 'New York')
In this example, first the subquery returns multiple zips for NYC. Then
the primary query returns all store data from the stores table with any
of the zips that came back from the zips in the NYC subquery.
Additionally, this example uses column and table aliases which are
important to use when searching for data across several tables. Aliases
are necessary because there may be columns with the same field name in
both tables and only aliases ensure you actually get the output from the
fields you really wanted.
Plus, when you use the fields with PHP later, the fields have clear
meanings to you and you can even use the original aliased field names as
human readable row header titles in your resultant HTML.
Warmest regards,
Peter Sawczynec
Technology Director
PSWebcode
www.pswebcode.com
ps at pswebcode.com
718.796.1951
-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of thegeek
Sent: Monday, September 19, 2005 6:06 PM
To: NYPHP Talk
Subject: [nycphp-talk] Multiple query from out put
Well need some guidance here. Pretty much a beginer. Here is what I
would
like to do. 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.
So
am unsure how to format to make multiple queries from the original
zipcode
search. I can query the database (MySQL) with a single zip and get what
I
need but don't know where to start when to repeat that with a multiple
query. This is a volunteer non profit project with no money and no real
deadline so a good opportunity for me to learn.
Paul G
_______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org
More information about the talk
mailing list