To make it clear, I have a column named PartyCode in the party table. It contains codes like
AAAA0, AAAA1, AAAA2, AAAA3...
ABAB0, ABAB1, ABAB2..
So what I want is first 4 letters of code and it should not be repeated ie. AAAA, ABAB.
I have tried it with DISTINCT
and SUBSTR
keyword but unable to do this. So I want to know that is that possible to do in one select query?
Refer the following question.You'll be able to get a help from it.
Use "group by" instead of distinct:
select LEFT(partyCode,4) as code from parties group by code;
Distinct works too:
select distinct LEFT(partyCode,4) as code from parties;
So I don't quite know where your problem is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.