Created
August 22, 2012 19:32
-
-
Save johnweldon/3428603 to your computer and use it in GitHub Desktop.
SQLite Test Case for http://stackoverflow.com/a/12063689/102371
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE tempA; CREATE TABLE tempA ( style_cd CHAR(3), id_cd VARCHAR(15) ); | |
DROP TABLE tempB; CREATE TABLE tempB ( item_desc VARCHAR(50), item_num CHAR(4), style_cd CHAR(3), id_cd VARCHAR(15) ); | |
INSERT INTO tempA | |
SELECT 'A', 123456 | |
UNION SELECT 'A', 654321 | |
UNION SELECT 'B', 321456 | |
UNION SELECT 'A', 654123 | |
UNION SELECT 'C', 424242; | |
INSERT INTO tempB | |
SELECT 'item 1', 7, 'A', 123456 | |
UNION SELECT 'item 2', 14, 'B', 123456 | |
UNION SELECT 'item 2', 14, 'A', 123456 | |
UNION SELECT 'item 3', 23, 'A', 123456 | |
UNION SELECT 'item 2', 14, 'B', 654321 | |
UNION SELECT 'item 2', 14, 'A', 654321 | |
UNION SELECT 'item 6', 44, 'A', 654321; | |
SELECT '-------------BEFORE---------------'; | |
SELECT * FROM tempB; | |
DELETE FROM tempB | |
WHERE style_cd IN ( | |
SELECT b.style_cd | |
FROM tempB b | |
JOIN tempA a | |
ON b.id_cd = a.id_cd | |
AND b.style_cd = a.style_cd ); | |
SELECT '--------------AFTER---------------'; | |
SELECT * FROM tempB; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I modified to add more data....this is where it fails...
CREATE TABLE #tempA ( style_cd CHAR(3), id_cd VARCHAR(15) )
CREATE TABLE #tempB ( item_desc VARCHAR(50), item_num CHAR(4), style_cd CHAR(3), id_cd VARCHAR(15) )