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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:29:11+00:00 2026-06-03T23:29:11+00:00

Given the table foo : Num Letter ———— 1 A 1 B 1 B

  • 0

Given the table foo:

Num   Letter
------------
1     A
1     B
1     B
2     C
3     A
3     C
3     D

If I do SELECT * GROUP BY Num I of course get something like this:

Num   Letter
------------
1     A
2     C
3     A

What I’d like to refine this to is:

Num   Has_No_Letter_C
---------------------
1     Yes
2     No
3     No

There’s probably a simple SELECT IF () plus a ORDER BY, but I can’t see it right now…

In my real-world example, the resultant table is LEFT JOINed to another table and I want to be able to reject the No entries but keep the NULLs if my other table bar has a Num = 4 row.

  • 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-03T23:29:13+00:00Added an answer on June 3, 2026 at 11:29 pm

    Use SUM(condition) within the IF:

    SELECT   Num,
             IF(SUM(Letter = 'C'), 'Yes', 'No') AS Has_Letter_C
    FROM     my_table
    GROUP BY Num
    

    Your JOIN then becomes:

    SELECT   another_table.Num
    FROM     another_table LEFT JOIN my_table ON another_table.Num = my_table.Num
    GROUP BY another_table.Num
    HAVING   my_table.Num IS NULL OR SUM(my_table.Letter = 'C') > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have SELECT name FROM table which gives me something like foo
In my feature file I have something like this: Scenario: Things Given the table
Given a couple of simple tables like so: create table R(foo text); create table
In C# Given a hash table like {id:'1', name:'foo'} How can I dynamically create
I've got a table that looks like this: Foo FooId : int (PK) BarId
I create quasi-boolean columns like this: CREATE TABLE foo bar NUMBER(1) DEFAULT 0 NOT
Given this HTML: <div id=TABLE1 class=tabs> <table> <tbody datasrc=Music> <tr id=randomid>lorem</tr> <tr id=foo>lorem</tr> <tr
Given a table row, I want to get the HTML out of the span
Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
Given a table like so: id | value ------------------- 1 | food 2 |

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.