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,343
  • 3
  • 18
  • 45

2 Answers2

1

Try below query

SELECT nh.CreatedBy,min(nh.InNeoHistoryId)
FROM NeoHistory nh group by nh.CreatedBy
Fahmi
  • 37,315
  • 5
  • 22
  • 31
1

Just make a small tweak to your query:

SELECT MIN(nh.InNeoHistoryId), nh.CreatedBy
FROM NeoHistory nh
GROUP BY nh.CreatedBy
Salman A
  • 262,204
  • 82
  • 430
  • 521