문제

I have this query

select distinct Name,ID from tbl_abc where Name like '%william jam%'

My expected result is

Anderson William James   1
William James            2

and the result coming is

Anderson William James   1
William James            2
William James            3

The data present inside table is

Anderson William James   1
William James            2
William James            3

how can i achieve this. I am trying this from last 2 hours but not getting distinct name.

도움이 되었습니까?

해결책

select Name,ID
 from tbl_abc where Name like '%william jam%'
group by Name

다른 팁

You can achieve using GROUP BY and if you want ID of the latest record use MAX and for first use MIN of same names

For max

select Name, MAX(ID) from tbl_abc where Name like '%william jam%' GROUP BY Name

For min

select Name, MIN(ID) from tbl_abc where Name like '%william jam%' GROUP BY Name
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top