![]() Make sure to GROUP BY and ORDER BY your results at your convenience. That would give you every basket color containing a fruit over 300 grams. Or something else, like a SELECT table_lor FROM mix_fruitbasket INNER JOIN table_basket USING (id_basket) INNER JOIN table_fruit USING (id_fruit) WHERE table_uit_weight > 300 Here, you can SELECT in the table_fruit INNER JOIN mix_fruitbasket USING (id_fruit) an id_fruit WHERE mix_fruitbasket.id_basket is known. This means, the fruit 1 belongs to baskets 1, 2 and 3, fruit 2 belongs to basket 1, fruit 3 belongs to basket 2 and 3. This way, in the mix_fruitbasket table, you can have: The primary key of this table is the combination of "id_basket+id_fruit" mix_fruitbasket, with at least an id_fruit column and an id_basket column. table_fruit, with at least an id_fruit column a fruit may be contained in multiple baskets at once This means it works the other way around, where a basket can only contain one fruit and a fruit can be found (referenced) in multiple baskets!Ī "n to n" relationship can be understood as the following: Note: in Pete's example just above, the id_fruit is in the table_basket table. Or the other way around, you can SELECT the table_fruit.id_basket FROM the table_fruit WHERE the table_uit_name is Banana. The table_fruit.id_basket value contains the unique identifier for the basket the fruit is in (this unique fruit belongs to one basket, and it is the basket number X)įor instance, you can SELECT an id_fruit FROM the table_fruit WHERE table_fruit.id_basket is known. table_fruit, with at least an id_fruit column and an id_basket column (the id_basket is a REFERENCE from table_basket, and if your fruit MUST be placed in a basket, make it NOT NULL) table_basket, with at least an id_basket column a fruit may be contained in an existing basket and if so, in only one basketįor this, you would need the following tables: a basket may contain multiple fruits at once The columns are named for each fruit object and the basket names are stored in the corresponding fruit column.Ī "1 to n" relationship can be understood as the following: I have a another table called CrossRef which is empty except for a “RefID” column. I need to search “Banana” and get a list of the baskets that have Bananas in them. The user will be defining the names of the baskets and the names of the fruit by text entry. ![]() I have a table called “Baskets” and a table called “Fruit”. Let’s say I have a bunch of different fruit and I was to tell what fruit has been added to what basket. I’ll use fruit and fruit baskets to explain. Here’s a simple scenario of what I’m trying to accomplish. What I need to accomplish is get a list of the y objects that have consumed a x object. Any x object can be consumed or occur in any y object but only once in each y object. All x objects are in one table and all y objects are in another table. The names of each object, x and y, are unique. I have a number of objects (x) that are consumed by another object (y) in the DB. Could use some help with some SQLite code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |