In this post, I am going to share one demonstration to update the table data using a Subquery in the PostgreSQL.
This is very basic help but I have found that most of the beginners always try to find script a way to update the table using Subquery or Joins.
Below is a small demonstration:
Create two sample table for Employee:
CREATE TABLE tbl_EmployeeDetails
EmpID SERIAL PRIMARY KEY
,EmpName CHARACTER VARYING(50)
,TotalPerformanceCount INTEGER DEFAULT 0
CREATE TABLE tbl_EmployeePerformanceCounter
PerformanceCounterID SERIAL PRIMARY KEY
,RecordDateTime TIMESTAMP WITHOUT TIME ZONE
FOREIGN KEY (EmpID) REFERENCES tbl_EmployeeDetails(EmpID)
Insert a sample data into both the table:
INSERT INTO tbl_EmployeeDetails (EmpName)
INSERT INTO tbl_EmployeePerformanceCounter
Update the count of the employee performance counter using Subquery:
FROM (SELECT EmpID,SUM(PerformanceCounter) AS TotalCount
FROM tbl_EmployeePerformanceCounter GROUP BY EmpID) AS T
SELECT *FROM tbl_EmployeeDetails ORDER BY 1;
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.