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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:05:23+00:00 2026-05-15T23:05:23+00:00

I have a table that is similar to: cycle | id | name ——|——-|——

  • 0

I have a table that is similar to:

cycle | id    | name
------|-------|------
0     | 0012  | bob
s     | 0012  | bob
1     | 0012  | bob
0     | 6208  | sally
1     | 6208  | sally
0     | 3276  | jane
s     | 3276  | jane
1     | 3276  | jane
0     | 8736  | harry
s     | 8736  | harry

I need a query that will result in:

cycle | id    | name
------|-------|------
s     | 0012  | bob
0     | 6208  | sally
s     | 3276  | jane
s     | 8736  | harry

So only return rows that have a ‘cycle’ value of “s”, unless there is no value of “s” for a particular ‘id’ in which case it should return the row with the ‘cycle’ value of “0”.

  • 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-15T23:05:23+00:00Added an answer on May 15, 2026 at 11:05 pm
    SELCET cycle, id, name from tbl1 as t1 where cycle='s' or 
    (cycle=0 and (select count(cycle) from tbl1 as t2 where t2.id = t1.id and t2.cycle='s') <= 0)
    group by t1.cycle,t1.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table that looks like this: Table: Designer id: integer name:
I have a database table that essentially contains different types of things. I'll use
I have a table that contains partial data that is of no use to
I have a table that essentially stores revisions of certain datasets (i.e. edits back
I have a table that contains unfortuantely bad data and I'm trying to filter
I have a table that looks like this: comment_id, user_id, comment, last_updated. Comment_id is
I have a table in html with some tabular data. The thing is that
I have a small JavaScript function that (among other things) retrieves the ID of
I have a very simple update statement: UPDATE W SET state='thing' WHERE state NOT
I will use LINQ-to-SQL when the database is ready and use the entities there

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.