Hi
I have table with Location,Branch. I want those records in which Branch has more than 1 location
Thanks
Hi
I have table with Location,Branch. I want those records in which Branch has more than 1 location
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Jan 30, 2025, 11:11 AM
To retrieve records from a table where a
Branchhas more than oneLocation, you can use a SQL query with a GROUP BY clause and a HAVING condition.Subquery:
The subquery groups the data by
Branchand uses theHAVINGclause to filter branches with more than oneLocation.HAVING COUNT(Location) > 1ensures only branches with multiple locations are selected.Main Query:
The main query retrieves all records from the table where the
Branchis in the result of the subquery.For example see the next sample table:
Table:
LocationsTharunkumar MagudeeswaranPosted Jan 30, 2025, 7:57 AM
Here is the code you can use it to check records with branch having more than 1 location.
Muhammad Imran AnsariPosted Jan 30, 2025, 6:32 AM
Hi Ramco,
You can achieve this using SQL by grouping the records by
Branchand filtering those that have more than one distinctLocation.Amit MohantyPosted Jan 30, 2025, 6:31 AM
You can use GROUP BY and HAVING to filter records where a Branch has more than one Location.