![]() From the UNION operator, we know that all rows will be displayed from both the queries except the duplicate are once. The DISTINCT clause with UNION produced nothing extra as the simple UNION done. Here UNION ALL have to avoid the elimination of duplicate rows. Here in the above picture shows, only the employee_id and job_id surrounded the red rectangle are same in employees and job_history table and they all have appeared in the result set. Sample Output: employee_id job_id department_id If we want to display the present and previous details of jobs of all employees, and they may appear more than once, the following sqlite statement can be used. In SQLite the UNION operator returns the combined result from multiple SELECT statements into a single result set but exclude the duplicate rows where as the UNION ALL operator avoids the elimination of duplicate selected rows and returns all rows. The UNION ALL operator returns all the rows from both the queries and no duplication elimination happens. Pictorial presentation of UNION ALL operator The UNION ALL operator does not eliminate duplicate selected rows and returns all rows. Here in the above picture shows, only the employee_id and job_id surrounded the red rectangle are same in employees and job_history table, so it comes once in the output but the other employee_id and job_id are different in both the tables, so they come each. If we want to display the present and previous details of jobs of all employees once the following sqlite statement can be used.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |