Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help combining two queries into One 1

Status
Not open for further replies.

glrpfi

IS-IT--Management
Nov 15, 2002
51
US
We are building a linux application that uses aMySQL database. The code is written in C++, but we'd prefer that simple table queries all by MySQL. The two below queries need joining into a single one to lessen processor calls by half.

we have two tables as described:

table 1. Object_name. ID (object
id), IND (the number of the name for the object) and VALUE (the actual name) Several names can be valid for one object id, the IND shows what name number is for any given object ID.

table 2. Replicas ReplicaNUM and ObjectNum.

ID and ObjectNUM for anygiven object are identical.

the two queries are:

SELECT DISTINCT object_name.id FROM
object_name WHERE value = 'somestring'


and

SELECT replica.id FROM replica WHERE mother
= object_id_gained_from_1st_query AND id > number_passed ORDER BY (id) LIMIT 1

the effect is to take an object name {of which there may be any number for a given object_id, and find out what the lowest matching replica number is for the object id.


can anyone give me the sql query that would put both parts into one call?
 
Maybe something like

SELECT replica.id
FROM replica inner join object_name
on replica.mother = object_name.id
WHERE replica.id > number_passed
and value = 'something'
ORDER BY replica.id LIMIT 1

As you have columns named id in both tables you need to qualify it on all occurences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top