0

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
2
  • update your SQL query like: "SELECT UNIQUE artist_name FROM Sheet1" Commented Jun 2, 2020 at 9:49
  • why don't u use distinct? Commented Jun 2, 2020 at 9:49

3 Answers 3

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

Use distinct:

select distinct artist_name from sheet1

Comments

0

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

query="SELECT DISTINCT artist_name FROM Sheet1"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.