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

  • SEARCH
  • Home
  • 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 953863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:07:10+00:00 2026-05-16T00:07:10+00:00

I have a very simple task, but I cannot find any solution. I have

  • 0

I have a very simple task, but I cannot find any solution. I have two tables, ‘articles’ and ‘categories’

My article table look like this:

id | cat_id | title | content
1      1      Blah     Content 1
2      1      Blah2    Content 2
3      2      Blah3    Content 3

My categories table look like this:

id | title
1     Category 1
2     Category 2

You see I have 2 articles that have the same cat_id. I do not want with duplicate cat_id field. I cannot use DISTINCT, because I will get all articles, because I want all fields out.

so if i use DISTINCT like this:

SELECT DISTINCT a.id, a.cat_id, a.title, a.content FROM articles AS a

I will get everything out, but I want output like this

id | cat_id | title | content
2      1      Blah2    Content 2
3      2      Blah3    Content 3

Can someone help me please !!!

  • 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-16T00:07:11+00:00Added an answer on May 16, 2026 at 12:07 am

    This query will select the first article (lowest id) from each category

    SELECT a.* FROM Article a LEFT JOIN 
       Article a2 ON a.id<a2.id AND a.cat_id=a2.cat_id
    WHERE a2.id IS NULL
    

    It does an outer join with all other articles. The join clause only joins articles with the same category and with a smaller ID. When there are no matches (a2.id is NULL), then we have the article with the lowest ID for that category.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple task I am trying to do in Groovy but
This is a very simple task in every language I have ever used, but
I have a very simple task but got confused. I need my action to
It's very simple task, but I struggle for hours. I have parse xml from
It's very simple task, but somewhere is a mistake.. I can't find out it.
I have a very simple task: add the contents of a textField to an
I'm having some trouble doing a very simple task. I have a rich textbox
I have a very simple table called Member , which consists of the following:
I have a template filter that performs a very simple task and works well,
This is probably a very simple fix but I've been unable to find an

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.