tags:

views:

27

answers:

1

Is there any way to name the complete select as a table? I will try to explain what I am trying to do. I have this

SELECT
    *
    FROM
    `Databse1`.`table1`
    JOIN
    `Database2`.`table2`
    ON
    `table2`.`customerID` = `table1`.`customerID`
    WHERE
    `table1`.`recordID` IN (1,2,3,4)

I have another table, table3 that has these fields

customerID recordID

the recordID is foreign key to table1. What I want to do is in above query somehow enter customerID so it can get all the recordIDs. Is that possible?

+1  A: 

Sounds like you want a derived table

SELECT 
  *
FROM Table3 t3
JOIN  (SELECT
        *
       FROM `Databse1`.`table1`
       JOIN `Database2`.`table2` ON `table2`.`customerID` = `table1`.`customerID`
       WHERE
       `table1`.`recordID` IN (1,2,3,4)) t1 ON t1.customerID = t3.customerID
WHERE t3.customerID = [your customer id]
John Hartsock