beginning_php thread: Subqueries
Message #1 by WH Micro <wh_micro@y...> on Mon, 15 Apr 2002 14:25:36 -0700 (PDT)|
Sorry for the multiple questions in this post:
> > PostgreSQL.
Is PostgreSQL free? How difficult, compared to mySQL,
is it to use?
> Don't know what to do about the foreign keys but you
> simulate sub queries with the programming language
> most probably in this case ;), i.e, do a query,
> store the
> results in a php variable, then do another query
> with this
Ok! This is a good idea but, how am I going to do
This is what I am trying to accomplish with
select * from stats
where userID = ( select userID from user
where fname = 'John' and lname = 'Smith' )
This is I think I need to do please correct if wrong:
//connected to db
$result1 = mysql_query( "select userID, fname, lname
from user where fname='John' and lname='Smith'");
$rec = mysql_fetch_array( $result1 );
$result2 = mysql_query( "select * from stats where
//since theres suppose to be one record...
$record = mysql_fetch_array( $result2 );
print( "Stats for" . $rec["fname"] . $rec["lname"] . "
are:\n" . $record["ab"] . " " . $record["hits"] ....
Would this output what's expected?
Thanks everyone in advance for all your help.
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
Message #2 by "Nikolai Devereaux" <yomama@u...> on Mon, 15 Apr 2002 14:39:26 -0700|
> select * from stats
> where userID = ( select userID from user
> where fname = 'John' and lname = 'Smith' )
SELECT stats.* FROM stats, user
AND user.userID = stats.userID
SELECT * FROM stats
JOIN user ON stats.userID = user.userID
Message #3 by "Nikolai Devereaux" <yomama@u...> on Mon, 15 Apr 2002 17:46:46 -0700|
> Or this:
> SELECT * FROM stats
> JOIN user ON stats.userID = user.userID
I just realized that I didn't write the second query specific to John Smith.
Heads up if that's the version you try to use, ok?