Python/SQLite

[Python] SQLite3 distinct 중복제거

Pydole 2018. 8. 15. 21:13

 

Table

 

 alphabet

 value

 E

2

 B

2

 C

4

 D

1

 A

3

 E

4

 A

1

 D

3

 C

2

 B

1

 

 

 

alphabet 컬럼 중복 제거

 

c = conn.cursor()

rows = c.execute('''select DISTINCT alphabet from test''')

for row in rows:
	print(row)

-----------------------------------------------------------

('E',) ('B',) ('C',) ('D',) ('A',)

 

 

 value 컬럼 중복 제거

c = conn.cursor()

rows = c.execute('''select DISTINCT value from test''')

for row in rows:
	print(row)
----------------------------------------------------------
(2,)
(4,)
(1,)
(3,)