यदि आप प्रत्येक कॉलम को निर्दिष्ट नहीं करना चाहते हैं जिसका आप उपयोग कर सकते हैं NOT EXISTS ... NATURAL JOIN
।
चेतावनी! यह समाधान प्रदर्शन के दृष्टिकोण से सर्वश्रेष्ठ नहीं है। यह Oracle / PostgreSQL / SQLite / MariaDB 10.3.2 और इसके बाद के संस्करण पर काम करना चाहिए।
की स्थापना:
CREATE TABLE the_table(
id integer not null
,date_ date
,persons integer
,two_wheelers integer
,cars integer
,vans integer
,buses integer
, autos integer
);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (1, '21/JAN/2018',1,1,1,1,1,1);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (2, '21/JAN/2018',2,2,2,2,NULL,2);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (3, '21/JAN/2018',3,3,3,3,NULL,NULL);
SELECT * FROM the_table;
+----+-------------+---------+--------------+------+------+-------+-------+
| id | date_ | persons | two_wheelers | cars | vans | buses | autos |
+----+-------------+---------+--------------+------+------+-------+-------+
| 1 | 21/JAN/2018 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2 | 21/JAN/2018 | 2 | 2 | 2 | 2 | null | 2 |
| 3 | 21/JAN/2018 | 3 | 3 | 3 | 3 | null | null |
+----+-------------+---------+--------------+------+------+-------+-------+
और क्वेरी:
DELETE FROM the_table
WHERE NOT EXISTS (SELECT *
FROM the_table t1
NATURAL JOIN the_table t2
WHERE id = the_table.id);
आउटपुट:
+----+-------------+---------+--------------+------+------+-------+-------+
| id | date_ | persons | two_wheelers | cars | vans | buses | autos |
+----+-------------+---------+--------------+------+------+-------+-------+
| 1 | 21/JAN/2018 | 1 | 1 | 1 | 1 | 1 | 1 |
+----+-------------+---------+--------------+------+------+-------+-------+
DBFiddle डेमो