Using OrientDB 2.* with OrientSQL.
I have a simple graph with Class Users that has a number of properties (username, country, pets, etc). Each user also has outgoing friends edge. I want to select only the username and country from all users who are friends with a specific user.
My query so far:
SELECT EXPAND( BOTH('friends') ) FROM users WHERE #rid = #12:0
returns the full user objects for those who are friends of #12:0
I want only to return the username and country of those friends.
Am I missing something simple? Much appreciated!
You can:
select expand(both('friends').include('username', 'country'))
from #12:0
Note that you should:
select from #12:0
instead of:
select from Users where #rid = #12:0
A sub-query would work. I don't think there is any other way to do this.
Try this :
select
username, country
from (select
expand( both('friends') )
from
#12:0)
Related
So I have a table listing all kind of url types (for example: Facebook, Instagram, Twitter, etc.)
I want to achieve result similar to from this one:
select
url
,(case
when url like '%facebook%' then 'Facebook'
when url like '%instagram%' then 'Instagram'
....
end) as type
However the problem is the list goes on with around 30-40 items, and I don't want to list them all manually.
Is there any way to achieve this?
I'm thinking about using loop but can't get it right.
Thank you.
Not exactly an answer to your question, but maybe as an alternative you can use REGEXP_EXTRACT:
WITH test_table AS (
SELECT "https://www.facebook.com/qwe" AS url UNION ALL
SELECT "http://abc.instagram.com/zxc"
)
SELECT
url,
REGEXP_EXTRACT(url, r"^https?:\/\/([^\/?]+)") AS type
FROM test_table
EDIT:
Similar to Michel's brilliant suggestion you can create additional table with a list of domains and their search strings. But make sure that single url won't fall under several conditions otherwise such url will be duplicated in the output.
WITH test_table AS (
SELECT "https://www.facebook.com/qwe" AS url UNION ALL
SELECT "http://abc.instagram.com/zxc"
),
social_networks AS (
SELECT '%facebook%' as search_string, 'Facebook' AS type UNION ALL
SELECT '%instagram%', 'Instagram'
)
SELECT
url, social_networks.type
FROM test_table JOIN social_networks
ON test_table.url LIKE social_networks.search_string
I am using two SOQL query in Salesforce.
First Query: Select Id, FirstName, LastName from User where Id='00000ADFEDSFSRTGDR'
Second Query: Select IsFrozen from UserLogin where UserId='00000ADFEDSFSRTGDR'
Can we combine these two query into a single query. Please help me on this.
No. If you use "describe" calls on User or UserLogin you'll see they are linked but there's no "relationshipName" field in the describe's result. That's what's used to link, bit like table alias in normal database.
// No going "up"
System.debug(UserLogin.UserId.getDescribe().getRelationshipName());
// And no going "down" either
for(Schema.ChildRelationship cr : User.SObjectType.getDescribe().getChildRelationships()){
if(cr.getChildSObject() == UserLogin.sObjectType && cr.getField() == UserLogin.UserId){
System.debug(cr);
System.debug(cr.getRelationshipName());
}
}
So you can do
SELECT Id, Name,
(SELECT PermissionSet.Name FROM PermissionSetAssignments)
FROM User
because PermissionSetAssignment.AssigneeId has relationshipName. But not
SELECT Id, Name,
(SELECT IsFrozen FROM UserLogin)
FROM User
Going "up" doesn't work either. SELECT Account.Name FROM Contact works OK but SELECT IsFrozen, User.Name FROM UserLogin doesn't. Again - because there's no relationshipName in the describe results.
You'll have to query separately and link them them in code as Map<Id, User> for example.
Hi I am new to Salesforce SOQL. I am trying to relate a solution to the accounts but can't get it working. I have created a query but calling from API and executing following query returns me a 'Case' object
SELECT case.account.name
FROM case
WHERE id IN (
SELECT CaseId
FROM CaseSolution
WHERE SolutionId ='XXXXXXX'
)
What about querying the CaseSolution object and then Account Name details from the Case:
SELECT Case.Account.Name FROM CaseSolution WHERE SolutionId = 'XXXXXX' GROUP BY Case.Account.Name
I have the following simple query which shows I can access the field I want to filter by:
SELECT Id, Name, (SELECT HC4__IsSearchableExternally__c FROM Contacts)
FROM Account
However, what I really want to do is return only the Id and Name properties for Accounts that have at least one Contact where HC4__IsSearchableExternally__c is true. Is this possible to do with a Salesforce query?
Basically, I want to do something like the following (nonfunctional query):
SELECT Id, Name
FROM Account
WHERE (SELECT COUNT(Id) FROM Contacts WHERE HC4__IsSearchableExternally__c = true) > 0
Thanks for any help you can provide!
You can do this with a semi-join, e.g:
select id, name from account
where id in (select accountId from contact where HC4__IsSearchableExternally__c = true)
I am trying to select all comments ,feeds and feedcomments for an individual case.
The hierarchy is like
Case
|
CaseComment
|
FeedComments(commnets or feeds under a CaseComment)
I could not find any relation between CaseComments and FeedComments nor CaseComments and CaseFeeds.
How can I select all together in a soql or individual soqls which relates Case, CaseComment,CaseFeed,FeedComment?
EDIT
The query you've included in the comment looks good. I'd write it as something like that:
SELECT Id, Body, ParentId, Parent.CaseNumber, CreatedDate,
(SELECT Id, CommentBody, CommentType FROM FeedComments)
FROM CaseFeed
ORDER BY Parent.CaseNumber, CreatedDate
(this is sample output rendered in Real Force Explorer, a pretty neat tool)
If I'll click into the "2 records" bit I can drill down to the fields selected from FeedComment for "this" CaseFeed:
If your query renders differently for you (some stuff is blank) - maybe try this different editor or even go to https://workbench.developerforce.com
If only some comments contain text - they might be uploaded images for example - filter them by CommentType = 'TextComment'?
ORIGINAL
FeedComments(commnets or feeds under a CaseComment)
No, not really. FeedComment is a Chatter table that can link to many objects but CaseComment is not one of them.
Maybe study the Chatter Entity Relationship Diagram?
Anyway - relationship to feed* objects doesn't have a nice name exposed so we can't query it all in one go:
I think you'll need something like this:
SELECT Id, CaseNumber,
(SELECT Id, CommentBody FROM CaseComments),
(SELECT Id, Body FROM Feeds)
FROM Case
SELECT Id, FeedItemId, ParentId, CommentBody
FROM FeedComment
WHERE ParentId = :caseIdHere