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

  • Home
  • SEARCH
  • 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 6207661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:40:18+00:00 2026-05-24T05:40:18+00:00

Given a table T with |rowid| fld1 | fld2| |1 | 1 | 10

  • 0

Given a table T with

|rowid| fld1 | fld2|
|1    |  1   | 10  |
|2    |  1   | 20  |
|3    |  2   | 10  |
|4    |  3   | 20  |

if I want to get all the fld1 values with fld2 = 10 AND fld2 = 20.

This would only be fld1 – the only one with fld2 values 10 and 20.

Is my best way to go a subquery:

select * from T where fld2 = 10 and rowid in (select rowid from T where fld2 = 20); 

or is there a better query?

  • 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-24T05:40:19+00:00Added an answer on May 24, 2026 at 5:40 am

    I hope I have understood your question

    select * from table where fld1 in (
    select fld1 from table
    where fld2 in (10,20)
    group by fld1
    having count(distinct(fld2)) = 2)
    

    If you don’t need to retrieve all rows

    select fld1 from table
    where fld2 in (10,20)
    group by fld1
    having count(distinct(fld2)) = 2
    

    this query suffices.

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

Sidebar

Related Questions

Given table USER (name, city, age), what's the best way to get the user
Given a table (mytable) containing a numeric field (mynum), how would one go about
Given a table named person (in a MySQL database/schema), kind of like this one:
Given a table of logical resource identifiers (one per row), what is the best
Given a table row, I want to get the HTML out of the span
given this table and data: DECLARE @Table table (RowID int, RowCode char(1), RowValue int);set
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
I am trying to get the Default Constraints information for a given table. I
I'm trying to get the list of field names for a given table, to
Given following table: rowId AccountId Organization1 Organization2 ----------------------------------------------- 1 1 20 10 2 1

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.