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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:12:11+00:00 2026-05-26T11:12:11+00:00

Here is the db schema Tables- I want to write a query to search

  • 0

Here is the db schema

Tables-

enter image description here

I want to write a query to search all files which have a metadata value like(‘abc’)
and get a specific corresponding metadata value for that file.

So for above search for all files which have abc1 as one of the values and give me its corresponding ‘geo’ key’s value.
I know it can be done by a subquery. But want to find the most efficient way.

  • 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-26T11:12:12+00:00Added an answer on May 26, 2026 at 11:12 am

    Could look like this. Should be the most efficient way, too.

    SELECT m0.m_value
    FROM   metadata m
    JOIN   file_metadata fm ON fm.m_foreign_key = m.m_id
    JOIN   file_metadata fm0 ON fm0.f_foreign_key = fm.f_foreign_key
    --                      AND fm0.m_foreign_key <> fm.m_foreign_key
    --  may or may not be necessary, depending on the selectivity of 'geo'
    JOIN   metadata m0 ON m0.m_id = fm0.m_foreign_key
    WHERE  m.m_value = 'abc1'
    AND    m0.key = 'geo'
    

    Be sure to assign aliases to multiple instances of the same table in one query.

    For an overview of related query techniques see this lineup: How to filter SQL results in a has-many-through relation.

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

Sidebar

Related Questions

Heres the situation. I have 2 tables here of the schema: ID | COMPANY_NAME
Lets imagine I have the same database schema as here: http://www.databaseanswers.org/data_models/driving_school/index.htm If a customer
I have a one-to-one relationship but hibernatetool complains when generating the schema. Here's an
I want to query a set of tables based on the column name, type,
Here's a fun one. Occasionally we may want to find the tables consisting of
I have 2 tables with the same schema, one is just a table that
I have a project here that connects to an in-production database and grabs tables
I have a basic M:N setup with three tables: candidate, position, and candidate_position. Here's
I have a DB helper class which extends SQLiteOpenHelper and in onCreate, I want
Here is my Database schema and the tables I am trying to link, I

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.