cancel
Showing results for 
Search instead for 
Did you mean: 

Flexible Search Query with UNION does not work

0 Kudos
1,553

Hello,

I'm a beginner and I'm trying this query with union but it doesn't work and I don't understand where I'm wrong.

I followed what is explained here FlexibleSearch Tips and Tricks.

Both of the queries that make the union taken individually work fine but when i put them together with union It gives to me: cannot find (visible) type for alias uniontable within []

I also tried without the curly braces around uniontable.PK but it gives to me: Incorrect syntax near the keyword 'SELECT, so i think this is not the problem.

Thank you in advance for help.

SELECT {uniontable.PK} FROM
(
{{

SELECT {cn.PK}
FROM {
    CriticalNews AS cn
    LEFT JOIN news2pointofservice AS n2p ON {n2p.source}={cn.PK}
}
WHERE {cn.cooperative} = '8796093074984' AND {n2p.target} IS NULL

}}

UNION

{{

SELECT {cn.PK}
FROM {
    CriticalNews AS cn
    JOIN news2pointofservice AS n2p ON {n2p.source}={cn.PK}
    JOIN PointOfService AS pos ON {pos.PK}={n2p.target}
}
WHERE {pos.name} = '009192'

}}
)uniontable
former_member633554
Active Participant
0 Kudos

it may need more bracketing



SELECT {uniontable.PK} FROM (

({{

SELECT {cn.PK}
FROM {
    CriticalNews AS cn
    LEFT JOIN news2pointofservice AS n2p ON {n2p.source}={cn.PK}
}
WHERE {cn.cooperative} = '8796093074984' AND {n2p.target} IS NULL

}})

UNION

({{

SELECT {cn.PK}
FROM {
    CriticalNews AS cn
    JOIN news2pointofservice AS n2p ON {n2p.source}={cn.PK}
    JOIN PointOfService AS pos ON {pos.PK}={n2p.target}
}
WHERE {pos.name} = '009192'

}})
)uniontable



Accepted Solutions (0)

Answers (2)

Answers (2)

pavan_joshi1
Participant
0 Kudos

Hello,

I think 'uniontable' should not be used with braces.

Try and check.

Thanks

SELECT uniontable.PK FROM
0 Kudos
Thanks Leo, I tried your tips but unfortunately it still doesn't work