473,811 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hot to use one mysql query in a second mysql query

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.acc ess_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.
Jul 17 '05 #1
2 1572
"leegold2" <le*****@nospam .net> wrote in message
news:su******** *********@nwrdd c03.gnilink.net ...
How can I in PHP take a first query eg:

mysql> SELECT balloon_txt.acc ess_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';


I believe this query should work:

SELECT * FROM `balloon_rec` LEFT JOIN `balloon_txt` USING (`access_no`)
WHERE MATCH (`balloon_txt`. `access_no`,`ba lloon_txt`.`rec s_txt`) AGAINST
('robin')

Chris Finke


Jul 17 '05 #2
Christopher Finke wrote:
"leegold2" <le*****@nospam .net> wrote in message
news:su******** *********@nwrdd c03.gnilink.net ...
How can I in PHP take a first query eg:

mysql> SELECT balloon_txt.acc ess_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';

I believe this query should work:

SELECT * FROM `balloon_rec` LEFT JOIN `balloon_txt` USING (`access_no`)
WHERE MATCH (`balloon_txt`. `access_no`,`ba lloon_txt`.`rec s_txt`) AGAINST
('robin')

Chris Finke


I must thank you - it worked perfectly.
Lee G.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1234
by: Russ | last post by:
Hi, I'm doing some web development and have mysql (3.23.x) installed to test with (win2k, but I don't think this question is particularly platform specific). I have a reasonably complex query which I am trying to optimise. When I first startup mysql, and perform the query, it can take 10 or so seconds. However, further subsequent queries (sorting by the same column) return in a fraction of a second. This is true
0
3953
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
8
5156
by: wlcna | last post by:
mysql v4.0.16: I had been using mysql with innodb and thought that was fine, until i used it for something requiring a few - perhaps slightly involved - joins, and have now seen the performance become totally unacceptable. I have a query that takes over 35 seconds using mysql and innodb, for reasons that are completely a mystery to me, in a result set consisting of only a handful of items.
1
2832
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work. Despite entering the required lines to "my.ini" (the new my.cnf) through notepad AND MySQL Administrator, the cache does not work. So, today I took a peek at the 'Health' tab in MySQL Administrator.
8
2376
by: Fred | last post by:
Hello, Our website is currently developed in ASP/Mysql 4. The dedicated servers on which it is currently hosted arrive at saturation. Here is their configuration: - 1 server PIV 2,8Ghz 1GB RAM with IIS 5 on Windows 2000 - 1 server Bi-xeon 3Ghz, 512 MB with MySQL 4 on Windows 2003 The website makes approximately 10.000.000 of pages seen and 310.000
6
1843
by: Ridge Burner | last post by:
Can someone tell me which of these 2 SQL queries will be more efficient? I'm having a debate with another guy about which would be less resource intensive for MySQL. The first uses MySQL to pick a random row in a single statement: <?php $sql = "SELECT FROM myTable ORDER BY RAND() LIMIT 1"; $query = mysql_query($sql,$conn); ?>
0
1205
by: Mike Husler | last post by:
I have been tasked with copying data from our SQL Server to a local MySQL (windows). About 75 tables are involved. The data arrive in SQL Server at irregular cadences. Some every 1/2 second, some every 1 minute, etc. Each row is a time value and several other values associated with that time such as flux or counts. I created a DTS package that uses the "Transform Data Task" to push data to "Other Connection".
11
4290
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP table that displays all records in my database on this same page. This too works fine. I have my table set up so that there is a 7th field, called "rid" to act as a "record id" or unique identifying field. This is primary and auto-incremented. There...
3
1685
by: thesmithman | last post by:
Well, actually, I'm sure it's my code... I have a basic nested query: $query="INSERT INTO items (blah, blah, blah) VALUES ('$blah', '$blahblah', NULL)"; $result=mysql_query($query) or die("There was an error: ". mysql_error()); if($result){ echo '<h1>Success</h1> <p>You have added this item to the database.</p>';
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.