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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:52+00:00 2026-06-08T18:29:52+00:00

I am using SQLite and I’m not sure if this can be done. Consider

  • 0

I am using SQLite and I’m not sure if this can be done. Consider I have these table:

======>Table: Total_Table

_id    Name   Ingredients

0     "A"     "table_a"<br>
1     "B"     "table_b"

=====>Table: table_a

 _id    Name

 0      "a_1" <br>
 1      "a_2"

=====>Table: table_b

_id    Name
0      "a_1" <br>

The tables referenced in the rows of Total_Table have a different number of rows and are created as rows in Total_Table are added.

At the moment, I need to structure a query which will return rows from Total_Table.

But will search through the entries of the Ingredients tables.

For example, if I am looking for all rows in Total_Table which have a_1 in their Ingredients table, it would return rows 0,1 from Total_Table.

Currently, I am doing this by querying all rows of Total_Table, then iterating through those entries and querying each table individually, forming an array as I go.

This is pretty bad since the tables I am looking through are relatively large, and hurts performance.

Any ideas? Thanks!

  • 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-06-08T18:29:54+00:00Added an answer on June 8, 2026 at 6:29 pm

    I think you’ll find this easier with a slightly different database schema. SQLite is a relational database, so let’s try to store things accordingly. Basically, we’ll have 3 tables, one for Total_Table, one for your ingredients, and a table to map which ingredients to which instance in the Total_Table.

    Logically, it will look like this:

    Table: Total_Table
    
    _id    Name
    0      "A"
    1      "B"
    
    Table: Ingredients
    
    _id    Name
    
    0      "a_1"
    1      "a_2"
    
    Table: Total_Ingredients
    
    total_id  ingredient_id
    0         0
    0         1
    1         0
    

    The benefits here are many. First, you don’t need to create any tables at runtime. You’ll need exactly 3 tables, regardless of how many Total_Table entries you have. Second, it’s easy to query. Third, you’re not duplicating the name a_1 anywhere in the revised schema (this is called Database normalization).

    Then, your query would look like this. Note that in the sample data, a_1 has an id of 0, which we’ll use for querying purposes.

    select _id, Name from Total_Table where id in 
      (select total_id from Total_Ingredients where ingredient_id = 0)
    

    Update: Your other query is pretty similar if I understand correctly. So, you want the recipes which have some or all of a given ingredients. Suppose your subset includes ids 1, 5 and 7 for this example, the only change is to use an in clause.

    select _id, Name from Total_Table where id in 
      (select distinct total_id from Total_Ingredients where ingredient_id in (1,5,7)) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I' m using sqlite on iphone. I have table with 200 000 records. It'
I'm using SQLite, and I have a table for properties, and a table for
Using SQLite in PHP (thus using PDO), I have this code: try { $db
I'm using SQLite. I have a simple table id flag 1 y 2 y
I was newbie in using sqlite database android. and now I have a problem
I have started using SqLite recently, so I am relatively new to it. I
Using SQLite, this works fine. However, when I switch to MySQL, instead of クイン
Running Nh 3.2 using SQLite throws the following exception: ---> NHibernate.HibernateException: Could not create
I'm using SQLite with C API. On C API, I can check the result
I am using SQLite, TABLE A ( ID FileNAME FOLDERID ) TABLE B (

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.