Ingres nested query - nested

I try this:
select fielda from tableA A
left join (select
fieldB
from tableB
) B where A.fielda = B.fieldB
I have this error :
Une erreur s'est produite lors de l'exécution de la requête.
ERROR [42500] [CA][Ingres ODBC Driver][Ingres]Table 'select' does not exist or is not owned by you.
INFORMATIONS SUPPLÉMENTAIRES :
ERROR [42500] [CA][Ingres ODBC Driver][Ingres]Table 'select' does not exist or is not owned by you. (CAIIOD35.DLL)
How can I do?
Thank you !!

The correct syntax would use ON rather than WHERE following the subselect.
SELECT a.fielda from tableA a
LEFT JOIN (
SELECT fieldB
FROM tableB
) b ON b.fielda = b.fieldB

Related

Unable to get the Order and Order entry details using flex query

I am using below flexible search query to get the order and order entry details from Hybris (version1808)
select {o.code},{o.date},{o.date},{o.totalprice},{o.totalTAX}, {ev.code} from {
Order as o
JOIN OrderEntry as oe ON {oe.orderpk} = {o.PK}
JOIN EnumerationValue as ev on {o.status}={ev.pk}
JOIN Product as p ON {oe.productpk} = {p.PK}
}
where {o.versionID} is NULL
I am getting below error
cannot search unknown field 'TableField(name='orderpk',langPK='null',type=OrderEntry)' within type OrderEntry unless you disable checking
Is there anything that I am missing?
Change {oe.orderpk} to {oe.order} and {oe.productpk} to {oe.product}
SELECT {o.code},{o.date},{o.date},{o.totalprice},{o.totalTAX}, {ev.code} from {Order as o
JOIN OrderEntry as oe ON {oe.order} = {o.PK}
JOIN EnumerationValue as ev on {o.status}={ev.pk}
JOIN Product as p ON {oe.product} = {p.PK}
}
where {o.versionID} is NULL

Error: Error while compiling statement: FAILED: SemanticException line 1:undefined:-1 Invalid function 'replace'

I am using HIVE
I keep receiving the error message below whenever I run my code:
Error while compiling statement: FAILED: SemanticException line 1:undefined:-1 Invalid function 'replace'
Here is my code:
select
ecat.count_category, eact.count_eventaction, elabel.count_eventlabel,
g.*,h.* from db1.table1 g
join (select count(distinct eventcategory) count_category, g.session_id from db1.table1 g group by g.session_id ) ecat on ecat.session_id = g.session_id
join (select count(distinct eventaction) count_eventaction, g.session_id from db1.table1 g group by g.session_id) eact on eact.session_id = g.session_id
join (select count(distinct eventlabel) count_eventlabel, g.session_id from db1.table1 g group by g.session_id ) elabel on elabel.session_id = g.session_id
join (select replace(h.display_name, '\'', '') display_name, h.ncct_cat, h.ncct_cat_cd, h.ncct_trmnt_id, h.oop_proc_cd, replace(h.oop_diag_cd, '\'','') oop_diag_cd from db2.table2 h
where replace(h.display_name, '\'', '') = 'Ultrasound, Abdomen (Complete)' and
replace(h.client_code, '\'', '')='MASTER' ) h on
replace(h.display_name, '\'', '') = g.eventLabel and g.eventAction='ENCOUNTER';
Any ideas or suggestions as to why I keep receiving this error message? I am using HIVE.
Hive replace function is introduced starting from 1.3.0 version.
select replace(string("kkl'll"),'\'','')="kk";
false
Please check the hive version you are using in your environment.
To workaround this issue use regexp_replace fucntion.
select regexp_replace(string("kkl'll"),'\'','')="kk";
false

Rename column on Laravel 5.1 migration [SQL SERVER][Linux]

I'm writting a migration on Laravel 5.1 and after created a table I rename the table name and the columns, It works running the migration for a MySQL database but on SQL Server 2008 fails trying to rename the columns and outputs the next error:
Next Doctrine\DBAL\DBALException: An exception occurred while executing 'SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation,
CAST(prop.value AS NVARCHAR(MAX)) AS comment -- CAST avoids driver error for sql_variant type
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
JOIN sys.schemas AS scm
ON obj.schema_id = scm.schema_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
LEFT JOIN sys.extended_properties AS prop
ON obj.object_id = prop.major_id
AND col.column_id = prop.minor_id
AND prop.name = 'MS_Description'
WHERE obj.type = 'U'
AND (obj.name = 'roles' AND scm.name = SCHEMA_NAME())':
I need that the migration working on both databases. My migration code is:
public function up()
{
Schema::create('cat_tipo_usuario', function (Blueprint $table) {
$table->increments('id_tipo_usuario');
$table->string('txt_tipo_usuario');
$table->timestamps();
});
//Se renombra la tabla
Schema::rename('cat_tipo_usuario','roles');
//Se cambia el nombre de las columnas
Schema::table('roles',function($tabla){
$tabla->renameColumn('id_tipo_usuario','id');
$tabla->renameColumn('txt_tipo_usuario','nombre');
});
}
If I comment the lines where I rename the columns the migration runs correctly, so the driver and the connection are working well.
I think whats causing an issue is you renaming your primary key field.
Please test this migration to see if it solves your :
Schema::table('roles',function($tabla){
$table->dropPrimary('id_tipo_usuario');
$tabla->renameColumn('id_tipo_usuario','id');
$table->primary('id');
$tabla->renameColumn('txt_tipo_usuario','nombre');
});
I think if before renaming, you drop the primary key constraint, it should work out!

Subquery returns more than 1 row - Mysql with Visual Studio 2010

I have the next code in mysql:
("SELECT id_viaje,
(SELECT nombre
FROM unidades,
viaje
WHERE id_unidad = id_unidades),
(SELECT nombre
FROM empleados,
viaje
WHERE id_empleado = id_conductor),
(SELECT nombre
FROM empleados,
viaje
WHERE id_empleado = id_guarda),
(SELECT nombre
FROM ciudad,
viaje
WHERE id_ciudad = id_salida),
(SELECT nombre
FROM ciudad,
viaje
WHERE id_ciudad = id_llegada),
fecha_salida,
fecha_llegada
FROM viaje; ")
I have tried LIMIT 1 at the end of each one, I have replaced = with IN and i have no idea why is showing me this error:
22:30:30 SELECT ID_Viaje, (select Nombre from unidades, viaje where ID_Unidad IN (ID_Unidades)) , (select Nombre from empleados, viaje where ID_Empleado IN (ID_Conductor)) ,(select Nombre from empleados, viaje where ID_Empleado IN (ID_Guarda)) , (select Nombre from ciudad, viaje where ID_Ciudad IN (ID_Salida)) , (select Nombre from ciudad, viaje where ID_Ciudad IN (ID_Llegada)) , Fecha_Salida, Fecha_Llegada FROM viaje limit 1
Error Code: 1242 Subquery returns more than 1 row
Please I need help very quickly!
you need to use in operator when subQuery returns more than one row.But in your case the sub query is also a problem.Please try to use what suggested by Rachcha
This error is returned when your subquery returns multiple rows when it is supposed to return a single row.
Your subquery logic is completely wrong. When you put a subquery inside a SELECT statement, you must be sure that the subquery will always return zero or one row.
What you can do now is putting a LEFT JOIN and use a few aliases in your query, like this:
SELECT id_viaje,
u.nombre AS unidade_nombre,
e_con.nombre AS conductor_nombre,
e_grd.nombre AS guarda_nombre,
c_salida.nombre AS salida_nombre,
c_llegada.nombre AS llegada_nombre,
fecha_salida,
fecha_llegada
FROM viaje v
LEFT JOIN unidades u ON v.id_unidad = u.id_unidades
LEFT JOIN empleados e_con ON e.id_empleado = v.id_conductor
LEFT JOIN empleados e_grd ON e.id_empleado = v.id_guarda
LEFT JOIN ciudad c_salida ON e.id_salida = c_salida.id_ciudad
LEFT JOIN ciudad c_llegada ON e.id_llegada = c_llegada.id_ciudad
;
Try running this in MySQL Workbench first and only if it runs successfully there then you should put it into your application code.
Also note that my code is not supposed to run in the first attempt. Please make any applicable corrections before running this code.
Read more about MySQL joins and MySQL subquery

JPQL JOINS with nested SELECT

Can I do something like this on JPQL?
SELECT NEW com.MyDTO(p.a, p.b, q.c, q.d)
FROM
(SELECT r.* FROM MyDTO1 r ) p
LEFT OUTER JOIN
(SELECT s.* FROM MyDTO2 s ) q
ON p.x = q.y
or similar?
(Above query has mixed with native and JPQL, so don't misunderstand)
I'm having a problem with this part I think.
FROM
(SELECT r.* FROM MyDTO1 r ) p
When I'm trying to execute I'm getting this error.
Exception Description: Syntax error parsing the query [.....], unexpected token [(]
Thank you!
No, you can't. Quote from the documentation:
Note that HQL subqueries can occur only in the select or where
clauses.
Yes you can!
You have to use native queries. Here is an example:
emf = Persistence.createEntityManagerFactory("TEST")
EntityManager em = emf.createEntityManager();
String queryString = "SELECT ID FROM ( SELECT * FROM ADDRESS WHERE ID < 0)";
Query query = em.createNativeQuery(queryString);
List<BigDecimal> result = query.getResultList();

Resources