Hi
I have table OWHS with fields BplId,Location. I want list of those reocrd which BPlId has more than 1 Location
Thanks
Hi
I have table OWHS with fields BplId,Location. I want list of those reocrd which BPlId 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.
Muhammad Imran AnsariPosted Apr 2, 2025, 6:34 PM
Hello Ramco,
You can use the HAVING clause with GROUP BY to find BplId values that have more than one associated Location.
Good Luck!
Pavan NalluriPosted Apr 2, 2025, 6:05 PM
Explanation:
The above query displays the BplId for which Id there is count of Location greater than 1, we grouped teh resukt by id and then filtered it based on the count of location
Tuhin PaulPosted Mar 29, 2025, 3:59 PM
If you prefer not to use a subquery, you can achieve the same result using a
JOIN:Explanation of the Alternative Query
Subquery (
sub) :BplIdvalues with more than one distinctLocation, similar to the previous query.JOIN :
OWHS) is joined with the subquery on theBplIdcolumn.BplIdvalues matching those in the subquery are retrieved.Tuhin PaulPosted Mar 29, 2025, 3:58 PM
To retrieve records from the
OWHStable where theBplIdhas more than one uniqueLocation, you can use SQL. The query will involve grouping the data byBplIdand filtering those groups that have more than one distinctLocation.Explanation of the Query
Subquery (
INClause) :BplIdvalues that have more than one uniqueLocation.GROUP BY BplIdto group the records byBplId.HAVING COUNT(DISTINCT Location) > 1condition ensures that only thoseBplIdvalues with more than one distinctLocationare selected.Outer Query :
BplIdandLocation) from theOWHStable where theBplIdmatches the list ofBplIdvalues returned by the subquery.