Reputation: 83
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
Reputation: 122
Assuming this is a SQL query, the statement for removing repetition is DISTINCT
:
query="SELECT DISTINCT artist_name FROM Sheet1"
Upvotes: 0
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