I want to found (with left outer join) customers that this month haven't any order. i wrote it but it not work properly because of previous month record.why this happent?, please guid me.
For simple
I have two tables:
Table1
+------+------+
| col1 | col2 |
+------+------+
| 1 | a |
| 2 | b |
| 3 | c |
+------+------+
Table2
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
| 1 | x | 0 |
| 2 | y | 0 |
| 1 | x | 1 |
+------+------+------+
2 y 1
Record (
2,'y',1
), not inserted In Table2 and I want found it with Left Outer Join, like below.
SELECT * FROM table1
WHERE col1 NOT IN (SELECT col1 FROM table2
WHERE col3=1) AND col1 IN (SELECT col1 FROM table2);
+------+------+
| col1 | col2 |
+------+------+
| 2 | b |
+------+------+
CREATE TABLE `table1` (
`col1` int,
`col2` varchar(1));
CREATE TABLE `table2` (
`col1` int,
`col2` varchar(1),
`col3` int);
INSERT INTO table1 VALUES (1,'a'),(2,'b'),(3,'c');
INSERT INTO table2 VALUES (1,'x',0),(2,'y',0),(1,'x',1);
Best wishes.