DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to prevent duplicate count value for inner join
Ferhat Karataş
Ferhat Karataş

Posted on • Updated on

How to prevent duplicate count value for inner join

When you join two tables and you want to count only the first table, you can use the distinct command.

select a.OrderID, count(distinct a.Id) as Total from tblOrder a 
inner join tblOrderDetail b on a.OrderID = b.OrderID
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.