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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:53:04+00:00 2026-06-06T03:53:04+00:00

I have a query (a view actually) the normally should define a unique mapping

  • 0

I have a query (a view actually) the normally should define a unique mapping from key to value2.

select key, value1, value2
from tbl -- joins are left out here
where (1=1) -- left out here
order by key
;

and usually the result is something like

key       value1  value2
--------------------------
Harry     fish    blue
Sally     dog     green
Willy     dog     red

so I can map key to value2 uniquely.

But as it happens the underlying data may contain junk some day:

key       value1  value2
--------------------------
Harry     fish    blue
Harry     fish    black     -- <<< breaks uniqueness
Sally     dog     green
Willy     dog     red

I would like to add HAVING and/or GROUP BY expressions to identify the nun-unique rows easily. Because I have to do something with value2 in this case I have to aggregate it somehow — my idea is max.

Therefore an example result would be

key       value1  value2   count_value2
----------------------------------------
Harry     fish    blue     2
Sally     dog     green    1
Willy     dog     red      1

But as always, I am completely baffled by GROUP BY and its consorts. Where do I but it? Where and where the aggregations?

  • 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-06T03:53:05+00:00Added an answer on June 6, 2026 at 3:53 am

    something like this?

    select 
      key, 
      min(value1) as "a value1", 
      min(value2) as "a value2", 
      max(value2) as "another value2", 
      count(distinct value2) "number of value2"
    FROM tbl
    group by key
    having count(distinct value2) > 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ViewBag.People made up from a View; var query = db.Vw_INTERACTPEOPLE.Select(p =>
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a view with some joins in it. I'm doing a select from
i have small query as follows: If i will make view state property of
I have a simple query (in a mySQL view) that php is using to
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have created an indexed view: CREATE VIEW LogValueTexts WITH SCHEMABINDING AS SELECT ISNULL(LRVS_SLOG_ID*256+LRVS_IDX,0)
I have an app with Photos. Users can view photos directly from a link
I have a search box on a page (actually in a partial view though
I have a question on how to optimize a query. Actually, as I'm going

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.