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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:20:06+00:00 2026-05-30T12:20:06+00:00

I need to retrieve ListingId from the below table based on the search condition.

  • 0

I need to retrieve ListingId from the below table based on the search condition. Kindly help the best way to retrive the query for the conditions below

Note : ListingId can have any number of ExtrafieldId, So Searching ListingId is based on the dynamic ExtrafieldId

If (ExtrafieldId = 1 and Value = 1) => OUTPUT - 20, 22
If (ExtrafieldId = 1 and Value = 1) and (ExtrafieldId = 2 and Value = 7) => OUTPUT - 21
If (ExtrafieldId =4and Value = 1999) => OUTPUT - 20, 21, 23

and so on…

ListingId   ExtraFieldId    Value      
20  1   1      
20  2   4      
20  3          
20  4   1990       
21  1   2      
21  2   7      
21  3          
21  4   1990       
22  1   1      
22  2   4      
22  3          
22  4   2000       
23  1   NULL       
23  2   NULL       
23  4   1999    
  • 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-30T12:20:07+00:00Added an answer on May 30, 2026 at 12:20 pm
    SELECT
          t1.ListingID
    FROM 
          TableX AS t1 
    
      JOIN                                --- 2nd JOIN
          TableX AS t2
        ON 
          t2.ListingID = t1.ListingID 
    
      JOIN                                --- 3rd JOIN
          TableX AS t3
        ON 
          t3.ListingID = t1.ListingID 
    
    WHERE 
          (t1.ExtraFieldID, t1.Value) = (@ExtraFieldID_search1, @Value_search1)
    
                            --- 2nd condition
      AND 
          (t2.ExtraFieldID, t2.Value) = (@ExtraFieldID_search2, @Value_search2)
    
                            --- 3rd condition
      AND 
          (t3.ExtraFieldID, t3.Value) = (@ExtraFieldID_search3, @Value_search3)
    

    If you need 3 conditions, you’ll need to join the table to itself one more time (so 3 times in total)

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

Sidebar

Related Questions

I need to retrieve all rows from a table where 2 columns combined are
I need to retrieve data from one table and use it to retrieve data
I need to retrieve a record from a database, display it on a web
I need to retrieve a set of Widgets from my data access layer, grouped
I need to retrieve random rows from SQL Server database. I am looking for
I need to retrieve the date from a UIDatePicker (Preferably I would also like
I need to retrieve multiple objects from an external system. The external system supports
I need to retrieve data from two tables. the first is a list of
I need to retrieve some some raw HTML from a certain part of an
I need to retrieve values from CakePHP's config file database.php from one of my

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.