Connecting Tech Pros Worldwide Help | Site Map

Hot to use one mysql query in a second mysql query

leegold2
Guest
 
Posts: n/a
#1: Jul 17 '05
Appreciate any help- I want to make a 1st DB query, then I want to feed
those results into a second query - the results of the 2nd query are
then my output. I know it's possible w/a temporary table of the
1st....but I think there's a cleaner way. I tried nested SQL w/MYSQL 4.1
but it hasn't worked. So maybe w/2 sucessive querys w/PHP?? Thanks.


How can I in PHP take a first query eg:

mysql> SELECT balloon_txt.access_no FROM balloon_txt WHERE MATCH
(access_no, recs_txt) AGAINST ('robin');
+------------+
| access_no |
+------------+
| BT-1037.11 |
| BT-2540 |
| BT-1034.06 |
+------------+
3 rows in set (0.00 sec)

and use the result in a 2nd query eg:

mysql> SELECT * FROM balloon_rec WHERE access_no='BT-1034.06';
+------------+--------------------------------------------+----------------+------------+-------------------------------------------------------------------+
| access_no | title | author
| doc_date | elec_access
|
+------------+--------------------------------------------+----------------+------------+-------------------------------------------------------------------+
| BT-1034.06 | Status of Meteorological Sounding Balloons | Robert
Leviton | 1963-12-01 |
http://Databases/Balloon/Data/BT1034.06.pdf |
+------------+--------------------------------------------+----------------+------------+-------------------------------------------------------------------+

So the final result would be three recoeds outputted.
Christopher Finke
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Hot to use one mysql query in a second mysql query


"leegold2" <leegold@nospam.net> wrote in message
news:sumKc.6476$lz2.5388@nwrddc03.gnilink.net...[color=blue]
> How can I in PHP take a first query eg:
>
> mysql> SELECT balloon_txt.access_no FROM balloon_txt WHERE MATCH
> (access_no, recs_txt) AGAINST ('robin');
>
> and use the result in a 2nd query eg:
>
> mysql> SELECT * FROM balloon_rec WHERE access_no='BT-1034.06';[/color]

I believe this query should work:

SELECT * FROM `balloon_rec` LEFT JOIN `balloon_txt` USING (`access_no`)
WHERE MATCH (`balloon_txt`.`access_no`,`balloon_txt`.`recs_txt `) AGAINST
('robin')

Chris Finke




leegold2
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Hot to use one mysql query in a second mysql query


Christopher Finke wrote:[color=blue]
> "leegold2" <leegold@nospam.net> wrote in message
> news:sumKc.6476$lz2.5388@nwrddc03.gnilink.net...
>[color=green]
>>How can I in PHP take a first query eg:
>>
>>mysql> SELECT balloon_txt.access_no FROM balloon_txt WHERE MATCH
>>(access_no, recs_txt) AGAINST ('robin');
>>
>>and use the result in a 2nd query eg:
>>
>>mysql> SELECT * FROM balloon_rec WHERE access_no='BT-1034.06';[/color]
>
>
> I believe this query should work:
>
> SELECT * FROM `balloon_rec` LEFT JOIN `balloon_txt` USING (`access_no`)
> WHERE MATCH (`balloon_txt`.`access_no`,`balloon_txt`.`recs_txt `) AGAINST
> ('robin')
>
> Chris Finke[/color]
[color=blue]
>[/color]
I must thank you - it worked perfectly.
Lee G.
Closed Thread