SELECT Vertex WITH multiple Edges - orientdb

This is my schema:
My objective is capture that purple Vertex with name "Paragrafo" and have connection with the Vertex "1" AND "2", in this case will be the #29:426.
I tried:
SELECT EXPAND( BOTH( 'Contem' ) ) FROM Topico WHERE Assunto = '1' and Assunto = '2'
or
SELECT * FROM Topico WHERE Assunto = '1' and Assunto = '2'
or
SELECT FROM ( SELECT EXPAND(BOTHE('Contem')) FROM Topico WHERE Assunto='2' and Assunto = '1')
The AND operator make the query return None.
It's possible to make a query to do that?
I'm doing my schema right?
Thanks.

Try this:
select from Topico where out().<property_name> contains '1' AND out().<property_name> contains '2'
Hope it helps
Regards

Related

How to fix an expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.?

Hey I have this query
IF (select kmkood from or_arved_read where kmkood = '1' or kmkood = '14' or kmkood = '15' or kmkood = '6' )
BEGIN
SET #stat_vat = 21
IF (select kmkood from or_arved_read where kmkood = '2' or kmkood = '7' )
SET #stat_vat = 12
But it returns An expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.
how can i fix it?
Firstly, your IF doesn't have a boolean expression. The subquery returns a value (or more accurately for this scenario will return many and cause a different error) for the column kmkood, but then you don't do anything with that value. What value does that column need? The format should be something like this:
IF (SELECT SomeColumn FROM dbo.SomeTable WHERE... ) = 'SomeValue'
Also, if you have a BEGIN you need an END afterwards, which you don't have:
IF (SELECT SomeColumn FROM dbo.SomeTable WHERE... ) = 'SomeValue'
BEGIN
{Do several statements}
END
As, however, you are just doing a SET statement then you don't actually need the BEGIN and END statements.
I suspect what you are really after here, however, in an EXISTS:
IF EXISTS(SELECT 1 FROM dbo.or_arved_read WHERE kmkood IN (1,14,15,6))
SET #stat_vat = 21;
IF EXISTS(SELECT 1 FROM dbo.or_arved_read WHERE kmkood IN (2,7))
SET #stat_vat = 12;
You don't need all those ORs either, an IN works fine, and numbers shouldn't be in single quotes, so that makes things a bit shorter.

Reference same table from outer query in subquery sqlalchemy + geoalchemy2 ORM

I am trying to convert a query to an equal orm statement in sqlalchemy and geoalchemy2. I am struggeling how to get the reference for p1.geom into the subquery in the not exists clause.
SELECT p1.geom FROM polygons as p1
WHERE p1.column1 = 'something' AND NOT EXISTS(
SELECT 1 FROM polygons AS p2
WHERE p2.column2 = 'something else' AND ST_Intersects(p1.geom, p2.geom)
)
I already tried around a bit but the closest i got was something like this:
p1 = self._session.query(polygons.geom).filter_by(column1='something').subquery()
p2 = ~self._session.query(polygons.geom).filter(polygons.column2 == 'something else')\
.filter(polygons.geom.intersects(p1.c.geom)).exists()
result = self._session.query(polygons.geom)\
.filter_by(column1='something')\
.filter(p2)
What i got from it:
SELECT polygons.geom FROM polygons
WHERE polygons.column1 = 'something' AND NOT (EXISTS (
SELECT 1 FROM (
SELECT polygons.geom AS geom FROM polygons
WHERE polygons.column1 = 'something') AS anon_1
WHERE polygons.column2 = 'something else' AND (polygons.geom && anon_1.geom)))
Any ideas that could help?

How to select from subquery if column contains a specific value in postgre

I would like to ask if it is possible to select again from a result set if a column contains a specific value?
For example, from the below query I want to select it as subquery and check if that subquery's first column contains both 2 and 3 result. Otherwise, no values should be return.
select e.evaluator_id, ROUND(avg(cast(e.rating_score as int))::numeric,1)::varchar, c.q_category_name
from tms.t_evaluation e
inner join tms.m_q_category c
on e.nendo=c.nendo
and e.q_category_id = c.q_category_id
and c.delete_flg = '0'
inner join tms.m_q_subcategory qs
on e.q_category_id = qs.q_category_id
and e.q_subcategory_id = qs.q_subcategory_id
and c.nendo = qs.nendo
and qs.delete_flg = '0'
where e.nendo = '2018'
and e.empl_id = 'empl05'
and e.delete_flg = '0'
and e.evaluator_id in ('2' , '3')
group by e.empl_id, e.nendo, e.q_category_id,
c.q_category_name, e.evaluator_id, e.history_no
Result contains both 2 and 3 in first column. Is this possible?
select e.evaluator_id, ROUND(avg(cast(e.rating_score as int))::numeric,1)::varchar, c.q_category_name
from tms.t_evaluation e
inner join tms.m_q_category c
on e.nendo=c.nendo
and e.q_category_id = c.q_category_id
and c.delete_flg = '0'
inner join tms.m_q_subcategory qs
on e.q_category_id = qs.q_category_id
and e.q_subcategory_id = qs.q_subcategory_id
and c.nendo = qs.nendo
and qs.delete_flg = '0'
where e.nendo = '2018'
and e.empl_id = 'empl05'
and e.delete_flg = '0'
and e.evaluator_id in (select case when evaluator_id=2 or evaluator_id=3 then evaluator_id else null from t_evaluation order by evaluator_id asc)
group by e.empl_id, e.nendo, e.q_category_id,
c.q_category_name, e.evaluator_id, e.history_no

Run function with select statement

I have a tabe valued function called "GetLogInfosMsg" which I want to run provided with some Parameters from a specific table. The code below does not work; I get the message "Only one expression can be specified in the select list when the sub-query is not introduced with EXISTS.". Can somebody help me? Thanks.
SELECT
#pErrMsgID = [MsgID],
#pParams = [Params]
FROM
[dbo].[GetLogInfoMsg]((SELECT
[FIELD1],
[FIELD2],
[FIELD3]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID));
try this
you have to pass parameter in separate not in table format
SELECT #pErrMsgID = [MsgID] ,
#pParams = [Params]
FROM [dbo].[GetLogInfoMsg](( SELECT [FIELD1]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
), ( SELECT [FIELD2]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
), ( SELECT [FIELD3]
FROM [dbo].[TABLE1]
WHERE [TABLE1].[UUID] = #pUUID
)) ;
If you are using mssql 2005+ consider using this:
SELECT
#pErrMsgID = t2.[MsgID],
#pParams = t2.[Params]
FROM [dbo].[TABLE1] t1
CROSS APPLY (SELECT [MsgID], [Params]
FROM [dbo].[GetLogInfoMsg] (t1.FIELD1, t1.FIELD2, t1.FIELD3) t2
WHERE t1.[UUID] = #pUUID

UNION and NOT IN Mysql Operation with Zend framework

I need to execute the following mysql query in Zend;I am not an excpert with Zend framework
SELECT `optionride`.`featureoption_id`,
`optionride`.`featureoptionride_id`,`foption`.`featureoptionblock_id`,
`foption`.`labelname`,`optionride`.`value` FROM
`engine4_ride_featureoptionrides` AS `optionride`
LEFT JOIN `engine4_ride_featureoptions` AS `foption`
ON foption.featureoption_id = optionride.featureoption_id
WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )
UNION
SELECT `foption`.`featureoption_id`, null as
`featureoptionride_id`,`foption`.`featureoptionblock_id`,
`foption`.`labelname`,null as `value` FROM `engine4_ride_featureoptions` AS `foption`
WHERE (foption.featureoptiontab_id= '2' ) AND `foption`.`featureoption_id` NOT IN
(
SELECT `optionride`.`featureoptionride_id` FROM `engine4_ride_featureoptionrides`
AS `optionride`
LEFT JOIN `engine4_ride_featureoptions` AS `foption` ON
foption.featureoption_id = optionride.featureoption_id
WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )
)
Anybody can help me please.
You can put all your query asis in the $db->fetch().
Also you can use $db->select()->union(array($sql1, $sql2)), where $sql1, $sql2 can be $db->select() or a string ("select...").
For the NOT IN you can use $db->where('someField NOT IN (?)', array());