{"id":24960051,"url":"https://github.com/adi501/sql-server-logical-interview-questions","last_synced_at":"2026-02-05T15:32:07.492Z","repository":{"id":267751273,"uuid":"902236579","full_name":"adi501/SQL-Server-Logical-Interview-Questions","owner":"adi501","description":"SQL Server Logical Interview Questions","archived":false,"fork":false,"pushed_at":"2025-02-14T05:33:22.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T13:52:41.185Z","etag":null,"topics":["highest-salary-of-each-department-with-name-sql","innerjoin-crossjoin-fullouterjoin-with-same-data","rank-dense-rank-row-number","self-join-example"],"latest_commit_sha":null,"homepage":"","language":"SQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adi501.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-12T07:13:10.000Z","updated_at":"2025-02-14T05:33:26.000Z","dependencies_parsed_at":"2024-12-12T08:22:27.686Z","dependency_job_id":"2ee0f4e1-fff6-419f-9a32-393937a55aab","html_url":"https://github.com/adi501/SQL-Server-Logical-Interview-Questions","commit_stats":null,"previous_names":["adi501/sql-server-logical-interview-questions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adi501/SQL-Server-Logical-Interview-Questions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adi501%2FSQL-Server-Logical-Interview-Questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adi501%2FSQL-Server-Logical-Interview-Questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adi501%2FSQL-Server-Logical-Interview-Questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adi501%2FSQL-Server-Logical-Interview-Questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adi501","download_url":"https://codeload.github.com/adi501/SQL-Server-Logical-Interview-Questions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adi501%2FSQL-Server-Logical-Interview-Questions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29124801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T14:05:12.718Z","status":"ssl_error","status_checked_at":"2026-02-05T14:03:53.078Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["highest-salary-of-each-department-with-name-sql","innerjoin-crossjoin-fullouterjoin-with-same-data","rank-dense-rank-row-number","self-join-example"],"created_at":"2025-02-03T08:07:03.914Z","updated_at":"2026-02-05T15:32:07.476Z","avatar_url":"https://github.com/adi501.png","language":"SQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Left Outer Join Interview Question:**\n\n```create table tablea(Id int)  \ncreate table tableb(Id int)\n\ninsert into tablea values(1)  \ninsert into tablea values(1)   \ninsert into tablea values(1)    \ninsert into tablea values(2)    \ninsert into tablea values(2)    \ninsert into tablea values(3)    \ninsert into tablea values(4)   \n\ninsert into tableb values(1)    \ninsert into tableb values(1)    \ninsert into tableb values(2)    \ninsert into tableb values(2)    \ninsert into tableb values(4)    \n\nselect * from tablea    \nselect * from tableb    \nselect * from tablea left outer join tableb on tablea.Id =tableb.Id\n```\n![image](https://github.com/user-attachments/assets/ca498800-e041-4cc7-bf0a-691e9bbeaeb6)\n\n\n**Self join in sql example (employee manager)**\n```\ncreate table tbl_EMP(Id int , Name varchar(10),Manager int)\n\ninsert into tbl_EMP values(1,'adi',0)\ninsert into tbl_EMP values(2,'anil',1)\ninsert into tbl_EMP values(3,'vani',2)\ninsert into tbl_EMP values(4,'abc',null)\n\nselect * from tbl_EMP\n\nselect E.Id,E.Name,M.Name as Manage from tbl_EMP E left outer join tbl_EMP M on E.Manager=M.Id\n\n--select E.Id,E.Name,M.Name as Manage from tbl_EMP E  join tbl_EMP M on E.Manager=M.Id\n\n--select E.Id,E.Name,M.Name as Manage from tbl_EMP E , tbl_EMP M where E.Manager=M.Id\n```\n![image](https://github.com/user-attachments/assets/085d8519-02e8-4226-8fcb-dd9bb10bd353)\n\n**Rank, Dense rank and Row Number in SQL Server**\n```\ncreate table tbl_EXP1(Id int)\n\ninsert into tbl_EXP1 values(1)\ninsert into tbl_EXP1 values(1)\ninsert into tbl_EXP1 values(2)\ninsert into tbl_EXP1 values(3)\n\nselect * from tbl_EXP1\n\nselect Id, \nrow_number() over(order by Id) as 'Row Number',\nRANK() over(order by Id) 'Rank',\ndense_rank() over(order by Id) 'Dense Rank' from tbl_EXP1\n```\n![image](https://github.com/user-attachments/assets/646aff1c-6187-4abd-b2e5-ffc92257a8d0)\n\n**Inner Join, Cross Join and Full Outer Join with same data in both tables**\n\n```\ncreate table tbl1(Id int)\ncreate table tbl2(Id int)\n\ninsert into tbl1 values(1)\ninsert into tbl1 values(1)\ninsert into tbl1 values(1)\n\ninsert into tbl2 values(1)\ninsert into tbl2 values(1)\ninsert into tbl2 values(1)\n\nselect * from tbl1\n\nselect * from tbl2\n\nselect t1.Id,t2.Id from tbl1 t1 inner join tbl2 t2 on t1.Id=t2.Id\n\nselect t1.Id,t2.Id from tbl1 t1 full outer join tbl2 t2 on t1.Id=t2.Id\n\nselect t1.Id,t2.Id from tbl1 t1 cross join tbl2 t2 --on t1.Id=t2.Id\n```\n![WhatsApp Image 2024-12-11 at 20 04 31_c9179935](https://github.com/user-attachments/assets/52c3c6ba-170d-4fad-b04c-6c070aeff356)\n\n**Find the Highest Salary of Each Department with EMP Name**\n```\n\n\n--create table Tbl_EMP(Id int identity(1,1),Name varchar(20),DepName varchar(20),Sal int)\n\ninsert into Tbl_EMP values('A','IT',2000)\ninsert into Tbl_EMP values('B','IT',3000)\ninsert into Tbl_EMP values('C','HR',5000)\ninsert into Tbl_EMP values('D','HR',7000)\ninsert into Tbl_EMP values('E','BPO',2000)\ninsert into Tbl_EMP values('F','IT',9000)\ninsert into Tbl_EMP values('G','IT',9000)\n\nselect * from Tbl_EMP order by DepName ,sal desc\nselect * from (select *,row_number() over(partition by DepName order by sal desc) as rowNum from tbl_emp) as t where t.rowNum in(1)\n\n\n--select * from (select *,rank() over(partition by DepName order by sal desc) as rowNum from tbl_emp) as t where t.rowNum in(3)\n--select * from (select *,Dense_rank() over(partition by DepName order by sal desc) as rowNum from tbl_emp) as t where t.rowNum in(3)\n\n--select *,row_number() over(partition by DepName order by sal desc) as rowNum from tbl_emp\n--select *,rank() over(partition by DepName order by sal desc) as rowNum from tbl_emp\n--select *,Dense_rank() over(partition by DepName order by sal desc) as rowNum from tbl_emp\n```\n![image](https://github.com/user-attachments/assets/19d40745-06ea-42cc-8e48-05636f3eae98)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadi501%2Fsql-server-logical-interview-questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadi501%2Fsql-server-logical-interview-questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadi501%2Fsql-server-logical-interview-questions/lists"}