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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:29:42+00:00 2026-05-28T13:29:42+00:00

SELECT userid,SUBSTRING_INDEX(SUBSTRING_INDEX(data, ‘\!’, -1), ‘!\’, 1)+0 AS num FROM table WHERE type=2 ORDER BY

  • 0
SELECT userid,SUBSTRING_INDEX(SUBSTRING_INDEX(data, '\"!', -1), '!\"', 1)+0 AS num 
FROM table
WHERE type=2
ORDER BY num DESC LIMIT 5

This picks up the number between !x! in a string and tries to return the number and order the rows by that number. It works fine.

However, I don’t know how to return unique user ids.

Adding ORDER BY userid returns the rows without ordering by num:

SELECT userid,SUBSTRING_INDEX(SUBSTRING_INDEX(data, '\"!', -1), '!\"', 1)+0 AS num 
FROM table
WHERE type=2
GROUP BY userid
ORDER BY num DESC LIMIT 5

Distinct doesn’t work either:

SELECT DISTINCT(userid),SUBSTRING_INDEX(SUBSTRING_INDEX(data, '\"!', -1), '!\"', 1)+0 AS num 
FROM table
WHERE type=2
ORDER BY num DESC LIMIT 5

I am out of ideas..

Example:

id    userid     data
1       56       !100!
2       22       !90!
3       56       !200!

Result should be:

userid      num
56          200
22          90
  • 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-28T13:29:43+00:00Added an answer on May 28, 2026 at 1:29 pm
    SELECT userid,MAX(num) num FROM
    (SELECT userid,SUBSTRING_INDEX(SUBSTRING_INDEX(data, '\"!', -1), '!\"', 1)+0 AS num  
    FROM table 
    WHERE type=2) A
    GROUP BY userid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql statement: SELECT userid,username FROM table1 ORDER BY userid DESC LIMIT
Please help me convert this to a lambda expression SELECT [UserID], MAX(Created) Created FROM
Given that I have a table contains user data, like this: userID calltime result
I have this sql statement SELECT userID from users WHERE (name='name1' AND username='username1') OR
The query is this one: SELECT FriendID FROM Relationships WHERE UserID = 1 INTERSECT
I have query like this: SELECT * FROM activity WHERE (((userId = 1 OR
Hi all is it possible to rewrite query: select userid from User where userid
I used the following query to find duplicates: SELECT userID, COUNT(userID) AS NumOccurrences FROM
This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
This is a dummy script : create table #tempLogs ( UserId int identity(1,1) primary

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.