In general, you can't write a single SQL query that uses multiple databases. You can however write queries that use multiple tables. You haven't written why you need run the query across two databases or why those tables are in separate databases when they are going to be used together, so I'll leave that for another time and answer your question...

There are two relatively simple ways to handle this, each with its own benefits and trade offs.

You can copy the table of DB2 to DB1, and then run the query (excellent performance on the query, takes little time to migrate data for each execution, but no real change in execution time as data grows), or you can write two queries and merge them in Witango (quick performance on queries, quick and easy to get going, performance slows drastically as data grows beyond a couple of thousand rows due to repetition of queries).  

For the SQL query you could use something like:

SELECT
t1.name
t1.category
t1.detail
count(t2.iddest) as 'Count'
FROM
db1.table1 t1,
db1.table2 t2
WHERE
t1.category = "A"
AND t1.id = t2.iddest

For the Witango you could:

1/ Query Table 1 for all category A records and assign to table_1_results
2/ execute an <@rows> loop for each row in table_1_results and query table 2 for a count of records where iddest equals the id of the current row 

Regards,

Jason.

On 20/07/2005, at 5:00 AM, Isabelle wrote:

Hi everybody

i have a problem of programmation and i don't know how to resolve it :

i have 2 mysql db :

DB 1)
id : 1
name : toto
category : A
detail : blue

id : 2
name : titi
category : A
detail : pink

id : 3
name : rosie
category : B
detail : yellow

id : 4
name : peter
category : A
detail : yellow





DB 2)
id2 : 1
iddest : 1
idexp : 2
catdest : A

id2 : 2
iddest : 1
idexp : 3
catdest : A

id2 : 3
iddest : 2
idexp : 3
catdest : A


i would like to list the first mysql db with criteria category = A. that is easy, but i wnat to list too the count of searches in db number 2 with the same category and iddest = the id of the first db...

i don't know if my explication is easy to  understand.
maybe an exemple  of the result i want :

name  categorie  detail         count
toto        A        blue        2 (id2 = 1 +  id2 = 2)
titi        A        pink        1 (id2 = 3)
peter    A        yellow    0

of course rosie isn't in the list because she is in category B.

Anyone knows how to do that? is it possible ?
thanks
Isabelle

________________________________________________________________________



WITH IMAGINATION

Planning, Implementation and Management of Web Applications 


160 Pacific Highway North Sydney NSW Australia 2060

phone + 612 9929 9229 fax + 612 9460 4770 

web - www.wi.com.au email -  [EMAIL PROTECTED]



________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

Reply via email to