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 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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 2448
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 1, 20222022-06-01T01:45:33+00:00 2022-06-01T01:45:33+00:00

sql – Find individual values from a “group by having” query

  • 0

[ad_1]

I have a table containing approx 8,000 rows.

It has 15 columns in it and one of those is a “reference number”.

My goal is to find all rows that match each other, and for the matching rows, find out what the reference number is.

The reference number is a bit random and doesn’t really have a relationship to the rest of the data.

This is the SQL I have so far which gives me all the matching rows and count:

select 
count(*),
component,
privileges,
protocol,
authority,
score,
means,
difficulty,
hierarchy,
interaction,
scope,
conf,
integrity,
availability,
version
from 
data
group by
component,
privileges,
protocol,
authority,
score,
means,
difficulty,
hierarchy,
interaction,
scope,
conf,
integrity,
availability,
version
having count(*) >1
order by count(*) desc;

The row I have missed off the query, because I cannot get this to work as intended if I include it is reference_number I require the reference number for every row that comes through as a hit for this query. So, if the count(*) is 23 for one set of columns that matches the query, what is the reference number for all 23. That’s my problem and I’m not sure if I can do that with SQL.

I can make new tables, or views, I felt like a subquery might help at first, e.g.

select reference_number from
    (select 
    count(*),
    component,
    privileges,
    protocol....

etc

But that fails with:

ERROR:  subquery in FROM must have an alias

Any help appreciated. (I am using Postgresql if that helps).

[ad_2]

  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 9 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 11 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 10 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

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.