scalar-subquery

Replace comparison to scalar subquery by inner join or left/right join

夙愿已清 提交于 2021-01-29 04:29:10
问题 I need to write this query using inner joins or right/left joins but I don't know how to start: select * from radicados where asignado = (select estudianteid from estudiantes where usuario = (select usuarioid from usuarios where nombre = $nombre_usuario)) But I don't know how to do the same with joins. I think this must be something like: select * from radicados inner join usuarios on usuarioid=usuario 回答1: It appears you want something like this: select radicados.* from radicados join

Replace comparison to scalar subquery by inner join or left/right join

╄→гoц情女王★ 提交于 2021-01-29 04:22:07
问题 I need to write this query using inner joins or right/left joins but I don't know how to start: select * from radicados where asignado = (select estudianteid from estudiantes where usuario = (select usuarioid from usuarios where nombre = $nombre_usuario)) But I don't know how to do the same with joins. I think this must be something like: select * from radicados inner join usuarios on usuarioid=usuario 回答1: It appears you want something like this: select radicados.* from radicados join

scalar subquery in if statement Condition in PL/SQL

走远了吗. 提交于 2019-12-20 03:11:42
问题 I have an If Statement block similar to the below which is failing with the error - PLS-00103: Encountered the symbol "SELECT" when expecting one of the following.... Begin If (select count(*) from Table1) > 0 then dbms_output.put_line('Test'); end if; end; I have similar Case statement which works fine select case when (select count(*) from Table1) > 0 then 2 else 1 end from dual From what i have read in Oracle Documentation the if and when support a Boolean Expression, any ideas whether

scalar subquery in if statement Condition in PL/SQL

寵の児 提交于 2019-12-02 01:27:27
I have an If Statement block similar to the below which is failing with the error - PLS-00103: Encountered the symbol "SELECT" when expecting one of the following.... Begin If (select count(*) from Table1) > 0 then dbms_output.put_line('Test'); end if; end; I have similar Case statement which works fine select case when (select count(*) from Table1) > 0 then 2 else 1 end from dual From what i have read in Oracle Documentation the if and when support a Boolean Expression, any ideas whether Subqueries are supported in If Conditions. Note: The Statements have been simplified, i am not really

PostgreSQL 9.2 row_to_json() with nested joins

女生的网名这么多〃 提交于 2019-11-26 06:15:07
问题 I\'m trying to map the results of a query to JSON using the row_to_json() function that was added in PostgreSQL 9.2. I\'m having trouble figuring out the best way to represent joined rows as nested objects (1:1 relations) Here\'s what I\'ve tried (setup code: tables, sample data, followed by query): -- some test tables to start out with: create table role_duties ( id serial primary key, name varchar ); create table user_roles ( id serial primary key, name varchar, description varchar, duty_id