0

I scraped some data from a website, where I wanted the data to look like this:

company_name | location | tags 
----------------------------------
company1     | USA      | tag1, tag2
company2     | China    | tag3, tag4, tag5

But instead the scraper pulled data in this format:

company_name | location | tags 
----------------------------------
company1     | USA      | tag1
company1     | USA      | tag2
company2     | China    | tag3
company2     | China    | tag4
company2     | China    | tag5

How would I turn the current data I have what I want above?

1
  • 1
    What version do you have? ... you might be able to use GROUP_CONCAT on the tags. Commented Jul 11, 2020 at 1:27

2 Answers 2

2

You can use group_concat():

select company_name, location, group_concat(tags separator ', ')
from t
group by company_name, location;
Sign up to request clarification or add additional context in comments.

Comments

1

You can use GROUP_CONCAT(). For example:

select 
  company_name,
  location,
  group_concat(tags) as tags
from t
group by company_name, location

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.