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 9254749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:57+00:00 2026-06-18T11:32:57+00:00

Table name: groups id name 1 ONE 2 TWO 3 THREE 4 FOUR 5

  • 0

Table name: groups

id  name
1   ONE
2   TWO
3   THREE
4   FOUR
5   FIVE
6   SIX

Table name: titles

id  title           groups  isactive
1   First Title     1,2,4   yes
2   Second Title    2,5,7   yes
3   Third Title     3,1,2   yes
4   Fourth title    2,4,5   yes

Link column: id

QUERY:

SELECT 
 t.*, g.name
FROM 
 `titles` AS t, groups AS g 
WHERE 
  t.groups REGEXP CONCAT('^', g.id, '')
ORDER by title ASC, name ASC

Results:

id  title           groups  isactive    name
1   First Title     1,2,4   yes         ONE
4   Fourth title    2,4,5   yes         TWO
2   Second Title    2,5,7   yes         TWO
3   Third Title     3,1,2   yes         THREE

Now, the problem is I want to select only one title for each group, however, there might be duplicate group names like (id = 4 and 2) both assigned to group number TWO.

HOW TO ONLY SHOW THE ONE WITH HIGH ID? Then the result should be like this: (excluding id=2)

id  title           groups  isactive    name
1   First Title     1,2,4   yes         ONE
4   Fourth title    2,4,5   yes         TWO
3   Third Title     3,1,2   yes         THREE

I tried using this query also:

SELECT 
 t.*, g.name
FROM 
 `titles` AS t, groups AS g 
WHERE 
  t.groups REGEXP CONCAT('^', g.id, '')
GROUP by g.name
ORDER by t.id DESC 

or

ORDER by t.id ASC

But both showing:

id  title           groups  isactive   name
3   Third Title     3,1,2   yes        THREE
2   Second Title    2,5,7   yes        TWO
1   First Title     1,2,4   yes        ONE

PLEASE SEE DEMO – SQL FIDDLE

  • 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-06-18T11:32:59+00:00Added an answer on June 18, 2026 at 11:32 am

    Try this

    SELECT A.*, B.NAME FROM titles A
    JOIN (
             SELECT g.name, max(t.id) id
             FROM titles AS t, groups AS g 
             WHERE t.groups REGEXP CONCAT('^', g.id, '')
             group by g.name
         ) B on A.id = b.id
    

    SQL DEMO

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

Sidebar

Related Questions

I have the following two tables in my mysql database. Table Name: groups id
I have the following two table: -Groups- Id Name -Members- Id GroupId (Group.Id is
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I got two tables. A dealer table (id, name, etc.) and an event table
I have three tables in which two are master tables and other one is
I am trying to join two tables. One being the sys.databases table and the
So I have two seperate tables. In the first table, there are a bunch
So a rough structure of my two tables concered is as follows: Table one:
I have a MySQL table of names , which consists of two fields: name
I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT

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.