How to use Select in Gremlin query - graph

I would like to select Name and Code from 'INS" table and Phone_Number from "MC" table, When I execute this gremlin query this is just returning the last select item which is Phone_Number. Not getting Name and Code from INS table.
How to use two select in a single gremlin query, any help would be really appreciated.
:> graph.traversal().V().hasLabel('Product').has('Product_ID','39401').has('Customer_ID','98833838').out('has_Contact').as('MC').out('has_a_insurance').as('INS').select('INS').valueMap('Name','Code').select('MC').valueMap('Phone_Number')
Expected output is:
==>{INS={Name=[383838], Code=[98]}, MC={Phone_Number=[8383838383]}}
==>{INS={Name=[300333], Code=[32]}, MC={Phone_Number=[4830930303]}}
==>{INS={Name=[748332], Code=[32]}, MC={Phone_Number=[4537373728]}}
Thanks

You can use project:
g.V().hasLabel('Product').has('Product_ID','39401').has('Customer_ID','98833838')
.out('has_Contact').as('MC').out('has_a_insurance').as('INS')
.project('INS', 'MC')
.by(select('INS').valueMap('Name','Code'))
.by(select('MC').valueMap('Phone_Number'))

Related

subquery not working in documentdb

My following query is working..
SELECT d.pub_user.userid FROM d where d.pri_data.user.email="xxx#yyy.zzz"
This gives me result as below..
[
{
"userid": "1e4491ef27097262"
},.....
]
The following query is also working..
SELECT * FROM c WHERE c.pub_user.userid IN ("1e4491ef27097262")
But, when I try the following, it does not work..
SELECT * FROM c WHERE c.pub_user.userid IN (SELECT d.pub_user.userid FROM d where d.pri_data.user.email="xxx#yyy.zzz")
It gives an error.. Syntax error, incorrect syntax near 'SELECT'
Any help is sincerely appreciated.
Thanks
subquery is currently not supported. As per this answer, you can try to leverage a stored procedure.
When one start hitting joins or subquery is an early indicator that your data document structure is not optimal. I am however wondering why you cannot query by email without subquery in your final example. Like this
SELECT * FROM c WHERE c.pri_data.user.email="xxx#yyy.zzz"
If this is not possible because these data are in separate documents perhaps email could be added to the docments.

DQL script for using order by clause to get case insensitive values

How to write a DQL script for getting the case insensitive string values using order by.
select *from country order by lower(name) giving me error. Thanks for your help in advance

Can I loop over the results of an SQL query to use each value in another query all at once in SQL Developer?

What I want to achieve (if it is possible from SQL Developer) is that when I execute the script it do the following:
Run a SELECT statement that will return a list of IDs. Approx 270 records.
I need to use each of those IDs individually in another SELECT statement (in the WHERE clause) which will return some records. A few of this could result in over 17,000 records and some can be one.
Then each result from the second SELECT I want it to be exported to an excel or csv file into a folder at my pc.
I have both 'Select' ready but I don't know how to loop over the results of the first to grab each ID and use it in the second one. Also I don't know how to export automatically from the code.
You can use GROUP BY clause.
read more here:
http://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj32654.html
If the first SELECT returns you IDs only, and that's all you need for your second SELECT, just use IN clause providing your first SELECT query for the second one.
Example:
-- Your second select
SELECT
col1
,col2
,col3
,col4
FROM
second_table
WHERE
some_foreign_id IN (
-- Your first select
SELECT
id
FROM
first_table
WHERE
some_conditions...
)
In my opinion don't use PLSQL for this. In PLSQL the only way you can get an output of this by using a REFCURSOR (unless you dont use UTIL File package to do it). A simple SELECT WITH JOIN condition will suffice your requirement.
Test illustration
SELECT A.* FROM TABLE_A A, TABLE_B
WHERE A.COMMON_COLUMN = B.COMMON_COLUMN;
Hope this helped you in same way

Use result of query with single result in SELECT

I'm using Sqlite and I found out that INSERT does not return the just inserted record with the automatically created primary key.
To solve this issue I found out I can use SELECT last_insert_rowid(). This returns the value that I need.
I need this value to update a field in the record of my database.
Is there any way I could form a SELECT query that has the result of that query built in?
UPDATE events SET url='query executed' WHERE eventId = <value of above query should come here>
If SELECT last_insert_rowid() returns the value that you need then put it there as a subquery. Subquery must be in (your_subquery) brackets.

Basic SQL count with LINQ

I have a trivial issue that I can't resolve. Currently our app uses Linq to retrieve data and get a basic integer value of the row count. I can't form a query that gives back a count without a 'select i'. I don't need the select, just the count(*) response. How do I do this? Below is a sample:
return (from io in db._Owners
where io.Id == Id && io.userId == userId
join i in db._Instances on io.Id equals i.Id **select i**).Count()
;
The select i is fine - it's not actually going to be fetching any data back to the client, because the Count() call will be translated into a Count(something) call at the SQL side.
When in doubt, look at the SQL that's being generated for your query, e.g. with the DataContext.Log property.
Using the LINQ query syntax requires a select statement. There's no way around that.
That being said, the statement will get transformed into a COUNT()-based query; the select i is there only to satisfy the expression system that underlies the LINQ query providers (otherwise the type of the expression would be unknown).
Including the select will not affect the performance here because the final query will get translated into SQL. At this point it will be optimized and will be like select (*) from ......

Resources