有没有办法将完整的选择命名为表格?我会试着解释一下我想做什么。我有这个
SELECT
*
FROM
`Databse1`.`table1`
JOIN
`Database2`.`table2`
ON
`table2`.`customerID` = `table1`.`customerID`
WHERE
`table1`.`recordID` IN (1,2,3,4)
我有另一个表,table3有这些字段
的customerID 的recordId
recordID是table1的外键。 我想要做的是在上面的查询中以某种方式输入customerID 它可以获得所有的recordID。这可能吗?
答案 0 :(得分:1)
听起来你想要一个派生表
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]