Not really, then I would have to select child table with which to JOIN on
condition, based on the value of parent table.
CREATE TABLE parent(
id INTEGER PRIMARY KEY,
child_type INTEGER,
CHECK(child_type IN (1, 2))
);
CREATE TABLE child_1(
id INTEGER PRIMARY KEY,
my_value INTEGER,
I see, thank you for pointing out.
I wanted to use it on table with conditional relations with 3 different child
tables.
Though I could use a trick and fit data selection into one query, efficiently.
Alas I am forced to stick to 2 queries.
Thank you!
8 February 2016, 12:08:26, by "Clemens
Paul wrote:
> CREATE TABLE parent(
> CREATE TABLE child_1(
> CREATE TABLE child_2(
> CREATE TABLE parent_child_1_link(
> CREATE TABLE parent_child_2_link(
>
> now, depending on the child_type in the parent I want to select ...
Show your query. Or at least example data and the desired result.
Paul wrote:
> I am curious what is a particular reason that aliased columns in a query not
> visible to sub-queries?
Because the SQL standard says so.
> Of course it is possible to duplicate expression in sub-query ...
> But this would not be as efficient as to access result of already
Hello!
I am curious what is a particular reason that aliased columns in a query not
visible to sub-queries?
CREATE TABLE foo(
id INTEGER,
bar INTEGER
);
INSERT INTO foo VALUES(1, 2), (3, 4);
SELECT 1 as super_id, (SELECT bar FROM foo WHERE id = super_id);
Gives an error:
Error: no
select *
from parent P, parent_child_1_link L, child_1 C
where P.id = L.parent_id
and C.id = L.child_id
and P.child_type = 1
union
select *
from parent P, parent_child_2_link L, child_2 C
where P.id = L.parent_id
and C.id = L.child_id
and P.child_type = 2
It is a very
On Mon, Feb 8, 2016 at 3:38 AM, Paul wrote:
> I see, thank you for pointing out.
>
> I wanted to use it on table with conditional relations with 3 different child
> tables.
> Though I could use a trick and fit data selection into one query, efficiently.
> Alas I am forced to stick to 2 queries.
On Mon, Feb 8, 2016 at 12:47 AM, Paul wrote:
> Hello!
>
> I am curious what is a particular reason that aliased columns in a query not
> visible to sub-queries?
>
> CREATE TABLE foo(
> id INTEGER,
> bar INTEGER
> );
>
> INSERT INTO foo VALUES(1, 2), (3, 4);
>
> SELECT 1 as super_id,
8 matches
Mail list logo