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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:59:00+00:00 2026-05-11T23:59:00+00:00

The structure of the table testtable is id int primary key productid int attributeid

  • 0

The structure of the table “testtable” is

  1. id int primary key

  2. productid int

  3. attributeid int

  4. value varchar(250)

where productid is the unique id of a product,
attributeid is the unique id of attribute of a product e.g. size, quality,height, color
and ‘value’ is the value for the attribute

i have to filter a result. I achieve the requirement by this query.
But i am not able to make it in a query.

select a.* from dbo.testtable a
where a.attributeId=10 and a.[Value]='Romance'
and productId in
(
    select productId
    from
    dbo.testtable where attributeId =7 and [Value]='Hindi'
)

Need help to build this 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-11T23:59:01+00:00Added an answer on May 11, 2026 at 11:59 pm

    I think you have to do this in two steps:

    Step 1: extract product ids

    BooleanQuery query = new BooleanQuery();
    
    query.add(new TermQuery("attributeId", 7), BooleanClause.Occur.MUST); 
    query.add(new TermQuery("value", "hindi"), BooleanClause.Occur.MUST); 
    TopDocs docs = searcher.search(query, null, searchLimit);
    

    You then need to extract the productId from the docs

    Step 2: run query

    BooleanQuery query = new BooleanQuery();
    
    query.add(new TermQuery("attributeId", 10), BooleanClause.Occur.MUST); 
    query.add(new TermQuery("value", "Romance"), BooleanClause.Occur.MUST); 
    
    // build "IN" clause
    BooleanQuery pidQuery = new BooleanQuery();
    for( long productId : productIds ){
        pidQuery.add(new TermQuery("productId", productId), BooleanClause.Occur.SHOULD); 
    }
    query.add(pidQuery, BooleanClause.Occur.MUST); 
    TopDocs docs = searcher.search(query, null, searchLimit);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simplified table structure: TABLE products ( product_id INT (primary key, auto_increment),
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
My table structure is: TABLE `licenses` ( `id` int(11) NOT NULL auto_increment, `code` varchar(30)
I have tree structure table like, Table{Id, ParentId, Name} where Id is primary key,
I have a table with structure Table-a Id was primary key ID | Name
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
Assume a table structure of MyTable(KEY, datafield1, datafield2...) . Often I want to either
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
I have a MySQL database table with this structure: table id INT NOT NULL
I have a table structured like this: CREATE TABLE [TESTTABLE] ( [ID] [int] IDENTITY(1,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.