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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:44:46+00:00 2026-06-16T02:44:46+00:00

I have made a statement that used group by. Now, I need to know

  • 0

I have made a statement that used group by. Now, I need to know the details for every record but I need to perform this at one statement.

For example: I made the following query to query about the files that ends with _1 and share the same number:

SELECT number, COUNT(*) AS sum domains
FROM table
WHERE file LIKE ‘%_1’
GROUP BY number HAVING sum domains > 1

So, if I have the following table:

domain      |   file      | Number 
------------------------------------     
aaa.com     | aaa.com_1   | 111
bbb.com     | bbb.com_1   | 222
ccc.com     | ccc.com_2   | 111
ddd.com     | ddd.com_1   | 222
eee.com     | eee.com_1   | 333
qqq.com     | qqq.com_1   | 333

The result of the query is (the number that is shared by more than file and the count of the file(s) that ends with _1 and shared this number):

number | sum domains
------------------------
222    | 2
333    | 2

What I need to do is to print out the file names. I need:

number | file
------------------------
222    | bbb.com_1 
222    | ddd.com_1
333    | eee.com_1
333    | qqq.com_1

How can I do this since group by clause does not allow me to print the file(s) ?

  • 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-16T02:44:48+00:00Added an answer on June 16, 2026 at 2:44 am

    You can JOIN your query back against the main table as a subquery, to get the original rows and filenames:

    SELECT 
      main.number, 
      main.file
    FROM 
      table AS main
      /* Joined against your query as a derived table */
      INNER JOIN (
        SELECT number, COUNT(*) AS sum domains 
        FROM table
        WHERE RIGHT(file, 2) = '_1' 
        GROUP BY number 
        HAVING sum domains > 1
        /* Matching `number` against the main table, and limiting to rows with _1 */
      ) as subq ON main.number = subq.number AND RIGHT(main.file, 2) = '_1'
    

    http://sqlfiddle.com/#!2/cb05b/6

    Note that I have replaced your LIKE '%_1' with RIGHT(file, 2) = '_1'. Hard to tell which will be faster without a benchmark though.

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

Sidebar

Related Questions

I have a program i frequently use that is made with .NET. This program
I have made a jQuery toggle for a menu that I had in mind.
I have made an application for IPad in objective C. In this I am
i have made an application having entity framewrok. It is wpf application, now it
I have made a code that read data from flash Nand (without filesystem). fd
I have made a cart and the cart has remove item button, but the
I have made a String[] array by using String.split(.) . I am now trying
Its a simple login form that I have made using Classic ASP, where the
I have this code that I've been working on and when I run it
I have a variable that I got out of the database table like this:

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.