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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:37:37+00:00 2026-06-10T13:37:37+00:00

I have such a MYSQL table `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `screen_name` text

  • 0

I have such a MYSQL table

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `screen_name` text NOT NULL,
  `user_no` int(20) NOT NULL,
  `avatar` text NOT NULL,
  `name` varchar(50) NOT NULL,
  `location` varchar(50) DEFAULT NULL
  PRIMARY KEY (`id`)

I need to create an SQL query.

  • ORDER BY id DESC
  • GROUP BY screen_name
  • Get “name” and “screen_name” fields
  • id between $idmin and $idmax

I will compare the performance of nested query and JOIN query seperately.
Can you propose query words?
Thank you

Edit: For nested query I tried this:

SELECT `name`,`screen_name` FROM `mytable` WHERE `id` IN
(SELECT `id` FROM `mytable` WHERE `id` BETWEEN 100 AND 500 ORDER BY `id` DESC)
GROUP BY `screen_name`

I couldn’t write for joined type.

Edit2: Say it I have such rows:

  • id=1, screen_name=mike, name=uk
  • id=2, screen_name=albert, name=usa
  • id=3, screen_name=ash, name=uk
  • id=4, screen_name=albert, name=new_zelland

I need to get results like this:
id=4
id=3
id=1

  • 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-10T13:37:39+00:00Added an answer on June 10, 2026 at 1:37 pm

    Your query should be in this format:

    SELECT MAX(id) AS max_id, user_no, screen_name
    FROM table_name
    WHERE id BETWEEN $idmin AND $idmax
    GROUP BY screen_name
    ORDER BY MAX(id) DESC;
    

    SQLFIDDLE DEMO HERE

    or with sub-query:

    SELECT a.id, a.name, a.screen_name
    FROM example a
        INNER JOIN (SELECT screen_name, MAX(id) id
                    FROM example
                    WHERE id BETWEEN 1 AND 4
                    GROUP BY screen_name
                   ) b
            ON a.screen_name = b.screen_name
               AND a.id = b.id
    ORDER BY a.id DESC;
    

    SQLFIDDLE DEMO HERE

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

Sidebar

Related Questions

i have such mysql db table: id name surname number 1 emil asadi 26
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),
I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
Consider a table such as this: CREATE TABLE records ( id INT NOT NULL
I have a website where I display information from a mysql table such as
I have a simple table as below. CREATE TABLE `stats` ( `id` int(11) NOT
I have a table of player performance: CREATE TABLE TopTen ( id INT UNSIGNED
Suppose, we have a test table in MySql: CREATE TABLE `test_table` ( `_id` INT(10)
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why

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.