List:General Discussion« Previous MessageNext Message »
From:Robert Casey Date:June 17 2002 1:15pm
Subject:RE: queries within queries
View as plain text  
[snip]
  I made a query: the result are given back to me. Now I want to perform
  another query within these results.
[/snip]

I am pretty new to mysql (I have only been playing with it for about 2 weeks
now), but I had a similar problem and I recommend using a simple Perl script
(using the DBI module).  

Here is an example of a script that does a simple query and extracts the
results (which can then be used for another query)


   	# ------->  Set up necessary variables  <--------- #

	my $db="User_Information";
	my $server="localhost";
	my $field_name="user_name_id";
	my $db_name="User_Name";
	my $field_name="last_name";
	my $data_value="Doe";

   	# ------->  Make a connection to the server  <--------- #

	$dbh = DBI->connect("dbi:mysql:$db:$server", $username, $password,
{ RaiseError => 1 });

	# Set up a query to send to the database
	$query = "SELECT $id FROM $db_name WHERE $field_name=\'$data_value\'
";
	
	# ---------> Prepare and execute the query  <------- #
	$sth = $dbh->prepare($query);
	query:$sth->execute();

	# ---------> Recieve result from query  <------- #
	$id_from_db = $sth->fetchrow_arrayref;

	# --------> Finish up transaction and disconnect from database
<------- #

	$sth->finish();
	$dbh->disconnect() || die "couldn't close database: $!";


Hope that helps!

-----Original Message-----
From: W. Enserink [mailto:enserink@stripped]
Sent: Monday, June 17, 2002 8:33 AM
To: mysql@stripped
Subject: queries within queries


hi all,


I made a query: the result are given back to me. Now I want to perform
another query within these results.

Is this possible?


thx for all tips.

regards Wilbert

------------------------- 
Pas de Deux 
Van Mierisstraat 25 
2526 NM Den Haag 
tel 070 4450855 
fax 070 4450852 
http://www.pdd.nl 
info@stripped 
-------------------------

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <mysql-thread112182@stripped>
To unsubscribe, e-mail
<mysql-unsubscribe-Robert.Casey=fmr.com@stripped>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Thread
Working libmysqld.a for Tru64 5.1?Randall Severy16 Jun
  • Re: Working libmysqld.a for Tru64 5.1?Dan Nelson16 Jun
  • queries within queriesW. Enserink17 Jun
    • RE: queries within queriesNick Arnett17 Jun
  • Re: queries within queriesBhavin Vyas17 Jun
    • Re: queries within queriesTod Harter17 Jun
  • temporary tableWilbert Enserink18 Jun
    • Re: temporary tableVictoria Reznichenko18 Jun
  • Re: temporary tableSammy Lau18 Jun
RE: queries within queriesRobert Casey17 Jun
RE: temporary tableHendrik Schalekamp18 Jun