3

我想知道什么 VFP9 相当于 mySQL 'NOT IN'。

给你确切的目的。我有两个表,我想显示 table1 中没有在 table2 中出现的所有数字。

TABLE1
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10

TABLE 2
 2
 3
 4
 8
 9

RESULT:
 1
 5
 6
 7
 10

我编写了 mySQL 代码:

SELECT * FROM table1 WHERE table1.row1 NOT IN (SELECT row2 FROM table2)

现在这段代码无法在 vfp9 中运行,似乎它无法识别NOT或者我的代码存在缺陷。任何的想法。

4

4 回答 4

3

请尝试LEFT JOIN

SELECT t1.*
FROM table1 AS t1
LEFT JOIN table2 AS t2 ON t1.row1 = t2.row2
WHERE t1.row1 IS NULL;
于 2013-01-23T07:46:35.843 回答
1

试试这个:

SELECT * FROM Table1 Right JOIN table2 on Table1.row1 = Table2.row2 WHERE Table1.row1 is not null

我相信你的 Table1 和 Table2 是一个游标,

于 2013-01-23T07:51:19.763 回答
0

Tamar 的评论是正确的。尝试运行以下代码:

CREATE CURSOR table1 (row1 i)
CREATE CURSOR table2 (row2 i)
SELECT table1
FOR x=1 TO 10
    APPEND BLANK
    replace row1 WITH x
ENDFOR
SELECT table2
APPEND BLANK
replace row2 WITH 2
APPEND BLANK
replace row2 WITH 3
APPEND BLANK
replace row2 WITH 4
APPEND BLANK
replace row2 WITH 8
APPEND BLANK
replace row2 WITH 9
SELECT * FROM table1 WHERE table1.row1 NOT IN (SELECT row2 FROM table2) 

它工作正常。

于 2013-01-24T02:54:52.390 回答
-1

我创建了与您完全相同的值的 Table1 和 Table2。
我已经执行 SELECT * FROM table1 WHERE table1.row1 NOT IN (SELECT row2 FROM table2)
结果是1 5 6 7 10。
代码是对的,结果也是。

于 2013-03-01T07:32:24.140 回答