0

I have 2 columns in a table where column A has distinct records and column b does not i.e. column b could have multiple items of the same value in each row.

What I require is to only show distinct records based on column B. I do need both columns though as it will be an input in Crystal Reports but I don't care what value column A has.

CreatedBy column has multiple different values and I need to get those distinct values.

Query

SELECT DISTINCT nh.InNeoHistoryId,  nh.CreatedBy
FROM NeoHistory nh
GROUP BY nh.CreatedBy, nh.InNeoHistoryId

Result

enter image description here

Aleksandar Zoric
  • 1,097
  • 1
  • 12
  • 33

2 Answers2

1

Try below query

SELECT nh.CreatedBy,min(nh.InNeoHistoryId)
FROM NeoHistory nh group by nh.CreatedBy
Fahmi
  • 36,607
  • 5
  • 19
  • 28
1

Just make a small tweak to your query:

SELECT MIN(nh.InNeoHistoryId), nh.CreatedBy
FROM NeoHistory nh
GROUP BY nh.CreatedBy
Salman A
  • 248,760
  • 80
  • 417
  • 510