![]() WHERE SEP_EMPLOYEES.EMPLOYEE_ID = ALL_EMPLOYEES.EMPLOYEE_ID So now when we need to remove the data of SEP_EMPLOYEES from ALL_EMPLOYEES, we can write: DELETE FROM ALL_EMPLOYEES INSERT INTO ALL_EMPLOYEES (first_name, last_name, department) VALUES ('David', 'Willson', 'DBA') INSERT INTO ALL_EMPLOYEES (first_name, last_name, department) VALUES ('Stephen', 'Johnas', 'Senior Dev') Now let's feed some dummy data into these tables as: INSERT INTO ALL_EMPLOYEES (first_name, last_name, department) VALUES ('Sabyasachi', 'Mukherjee', 'IT Analyst') First we need to create the tables as: DROP TABLE IF EXISTS ALL_EMPLOYEES To solve our problem we discussed, we need to use this DELETE with USING. In the WHERE clause, use the columns from the tables in the USING clause to join the data (equivalent to join condition). ![]() After the USING clause, specify the table expression, which can be one or even more tables (equivalent to join).But we can use the USING clause with the DELETE statement to have the same functionality achieved. PostgreSQL does not support the DELETE JOIN statement. In this case, we need to do a conditional delete from the ALL_EMPLOYEES table. Now, the company wants to clean up their database of all the separated employees' information from the ALL_EMPLOYEES table. Suppose we also have a table, called SEP_EMPLOYEES, which contains those employees' information who have separated from the company. Suppose we have a table, called ALL_EMPLOYEES, which contains all employees' information who are working or had ever worked for the company. But we sometimes get confused when we need to insert or delete records conditionally from a table. ![]() We are comfortable with inserting/deleting record(s) into/from a table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |