Question

I mean the following: I have 2 parent tables :

table1 id PRIMARY KEY name TEXT

table2 id PRIMARY KEY ...

and a child table, used fo n-n Relations : table_child id PRIMARY KEY id_1 INT id_2 INT

where id_1 and id_2 in table_child refer to the column id in table1 and table2.

Now : i often perform request, with a join between table_1 and table_child ON table1.id = table_child.id1, only because i need the value of the column table1.name. I'm wondering if there is a way to avoid these joins, and declare somehow a "pseudo" column name in table_child, which would not be a real column, but a link to the corresponding column in table_1, so that : * I can acces the value through table_child.name * But it is always synchronized with the value table1.name

I hope my explanation was understandable...

Was it helpful?

Solution

Further to my comment above, the answer you're really looking for is something like:

CREATE VIEW
    table1_child_view AS
SELECT
    table1.name,
    table1_child.*
FROM
    table1_child
INNER JOIN
    table1 ON
        table1.id = table1_child.id_1

Then you can run your queries on the new view, such as:

SELECT name FROM table1_child_view WHERE ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top