如何检查一个表的id到另一个表?

时间:2016-02-25 09:45:22

标签: php mysql sql

如何使用php查找一个表的不同值id是否退出到另一个表。

例如:让table1拥有id(非主要或唯一)4564,{{ 1}},如何检查6的{​​{1}}是否有idtable24

5

3 个答案:

答案 0 :(得分:0)

这个SQL可能会有所帮助:

int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;

Excel.Range cell = null;

for (int iRow = 1; iRow < rowCount; iRow++)
{
    for (int iCol = 1; iCol <= colCount; iCol++)
    {
        /* This line of code is probably wrong */
        cell = xlRange.Cells[iRow, iCol] as Excel.Range;

        if(/*Cell contains PivotTable*/)
        {
            int rowLocation = iRow;
            int colLocation = iCol;
        }
    }
}

答案 1 :(得分:0)

SELECT table2.id 
FROM table2
WHERE table2.id IN (
    SELECT DISTINCT table1.id
    FROM table1
)

答案 2 :(得分:0)

要获取table1中作为table2中的id的所有项目代码的列表: -

SELECT DISTINCT table1.project_code  
FROM table1
INNER JOIN table2
ON table1.project_code = table2.id

从table1获取表2中所有项目代码的列表

SELECT DISTINCT table1.project_code  
FROM table1
LEFT OUTER JOIN table2
ON table1.project_code = table2.id
WHERE table2.id IS NULL

如果您想要的2上的条目不在1

SELECT DISTINCT table2.id  
FROM table2
LEFT OUTER JOIN table1
ON table1.project_code = table2.id
WHERE table1.project_code IS NULL