Skip to content
Advertisement

Tag: foreign-keys

How to retrieve data from two MySQL tables with multiple associations

I got these two tables where one table is having multiple foreign keys to the second table. Table rankings Table item One ranking record may have multiple association to item table using first_item_id, second_item_id, third_item_id or forth_item_id fields. I want to retrieve ranking records with the corresponding item_code instead of the item.id. What would be the most efficient way to

How to retrieve all grand parents at once

I have two simple tables in SQLITE3 (family bonds): “persons” (id, fname, lname) “relationships” (parent/child) I would like to get each grand children along with all their grand parents (from 1 to 4 of them depending on the grand child) so that 1 row result = Thanks to Caius Jard, I’ve been able to get each child and its grand

Is table order imporant in mysql when creating relation between them?

I have quite simple question. I am creating database administration tool, where user will be able to create relations between tables, but I am not sure if table order is important when creating relations. For example: I have two tables ‘user'(user_id(INT, PRIMARY KEY), name(VARCHAR), email(VARCHAR)) and ‘post'(post_id(INT, PRIMARY KEY), content(TEXT), author(INT)). When user has selected one column from both tables

Foreign and Primary Key Conceptual Questions

I am a newbie at SQL/PostgreSQL, and I had a conceptual question about foreign keys and keys in general: Let’s say I have two tables: Table A and Table B. A has a bunch of columns, two of which are A.id, A.seq. The primary key is btree(A.id, A.seq) and it has a foreign key constraint that A.id references B.id. Note

Advertisement