vvv-1234
vvv-1234

Reputation: 83

remove duplicates in python

I'm looking to remove the names that are repeated.

My code is connected to retrieve information from SQL server to Python.

def get_all_artist():
    query="SELECT artist_name FROM Sheet1"
    all_artist = execute_read_query (conn, query)
    for artist_record in all_artist:
        print(str(artist_record[0]))
    return (all_artist)

The artist_name that I am retrieving on SQL are:

BTS
BTS
BTS
TWICE
TWICE
TWICE
TWICE
TWICE
HEIZE
HEIZE
KHALID
KHALID
KHALID
ERIC CHOU
ERIC CHOU
ERIC CHOU
SAM SMITH
SAM SMITH
SAM SMITH
AGUST D

However, I'd only like to remove the duplicates on Python without removing any rows in my SQL table:

BTS
TWICE
HEIZE
KHALID
ERIC CHOU
SAM SMITH
AGUST D

Upvotes: 0

Views: 868

Answers (3)

Vijay
Vijay

Reputation: 122

Assuming this is a SQL query, the statement for removing repetition is DISTINCT:

query="SELECT DISTINCT artist_name FROM Sheet1"

Upvotes: 0

Md Sabbir Hossain
Md Sabbir Hossain

Reputation: 200

Use This Function and It Will Be work:

def get_all_artist():
    query="SELECT distinct artist_name FROM Sheet1"
    all_artist = execute_read_query (conn, query)
    for artist_record in all_artist:
        print(str(artist_record[0]))
    return (all_artist)

Upvotes: 1

GMB
GMB

Reputation: 222582

Use distinct:

select distinct artist_name from sheet1

Upvotes: 0

Related Questions