Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1034049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:19:45+00:00 2026-05-16T14:19:45+00:00

I have a table articles , another tags , and a third called article_tags

  • 0

I have a table articles, another tags, and a third called article_tags. I want to produce a page which lists all of the articles for a specific tag.

My query looks like this:

SELECT headline, GROUP_CONCAT(tags.tag_name) AS all_tags FROM articles
LEFT JOIN articles_tags ON articles.article_id = articles_tags.article_id
LEFT JOIN tags ON articles_tags.tag_id = tags.tag_id
WHERE tags.tag_name = 'japan'
GROUP BY articles.article_id

All of the returned articles only have japan as a tag, even when the article in question has several tags.

This is obviously related to the WHERE clause, but I can’t figure out how to do what I want here – ideally I’d end up with a list like japan,china,korea instead. Is this the place for a subquery? Could do with a SQL guru to advise.

Thanks,
Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:19:45+00:00Added an answer on May 16, 2026 at 2:19 pm

    There are at least two approaches you could use. One approach is to join with the tables twice. The other as you point out is to use a subquery. For simiplicity and ease of reading, I’d probably go with the subquery here. The resulting query would look something like this:

    SELECT
        headline,
        GROUP_CONCAT(tags.tag_name) AS all_tags
    FROM articles
    JOIN articles_tags ON articles.article_id = articles_tags.article_id
    JOIN tags ON articles_tags.tag_id = tags.tag_id
    WHERE articles.article_id IN (
        SELECT articles.article_id
        FROM articles
        JOIN articles_tags ON articles.article_id = articles_tags.article_id
        JOIN tags ON articles_tags.tag_id = tags.tag_id
        WHERE tags.tag_name = 'japan'
    )
    GROUP BY articles.article_id
    

    And here’s the approach using more JOINs:

    SELECT
        a.headline,
        GROUP_CONCAT(t2.tag_name) AS all_tags
    FROM articles a
    JOIN articles_tags at1 ON a.article_id = at1.article_id
    JOIN tags t1 ON at1.tag_id = t1.tag_id AND t1.tag_name = 'tag1'
    JOIN articles_tags at2 ON a.article_id = at2.article_id
    JOIN tags t2 ON at2.tag_id = t2.tag_id
    GROUP BY a.article_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are using nested forms, so nested params should work… May 17, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer <%= Url.Action("AcccountCreate", new { login = "guest" }) %> or… May 17, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer You're right that there is no difference between class and… May 17, 2026 at 12:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have tables, 1 called articles and another called links. I want to take
Lets say I have a table in MySQL called articles, that has a column
I have one table in my core data source which holds some articles with
I have a table for articles with several fields ,each article can have photo/photos
I have 1 table filled with articles. For the purpose of this post, lets
I have the table Articles -------- id,name,type_id Type--------------id,name article_type ----------article_id , type_id I using
I have two tables: articles and articletags articles: id, author, date_time, article_text articletags: id,
I have three mysql tables, first holds information about articles (Article ID, author ID,
after searching up and down, reading all possible articles and tutorials, I grasped the
I have in my MySQL database these two tables: CREATE TABLE IF NOT EXISTS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.