I need a query to take the name of the territory to which a user belongs I try with this  UserTerritory userT = [SELECT Id, Terrotory.Name                                     FROM UserTerritory                                     WHERE UserId = :currentUser LIMIT 1];  but throws this error  SELECT Id, Territory.Name            ^ ERROR at Row:1:Column:12 Didn't understand relationship 'Territory' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
123118
I want to get user and user's territory information. After i search, i found that user information in user Table. territory information in Territory Table. but, the relationship in UserTerritory Table. But, from the apex guide,i found that UserTerritory Don’t Support DML Operations. So, i can not get the information. So, Does anyone knows that how to write this soql or would you please give some idea to address this issue.   Many thanks
58239
I have the following query:  SELECT c.* FROM companies AS c JOIN users AS u USING(companyid) JOIN jobs AS j USING(userid) JOIN useraccounts AS us USING(userid) WHERE j.jobid = 123;   I have the following questions:   Is the USING syntax synonymous with ON syntax? Are these joins evaluated left to right?  In other words, does this query say: x = companies JOIN users; y = x JOIN jobs; z = y JOIN useraccounts; If the answer to question 2 is yes, is it safe to assume that the companies table has companyid, userid and jobid columns? I don't understand how the WHERE clause can be used to pick rows on the companies table when it is referring to the alias "j"   Any help would be appreciated!
119231
I'm in the data explorer, and I need my user ID for a query.  Problem is, I don't know what it is, if it's not my username.
78798
I have a table structured as so (Simplified)  Name, EMail, LastLoggedInAt   I have a user in SQL Server (RemoteUser) that should only be able to see data (Via a select query) where the LastLoggdInAt field is not null.   It looks like I can do this? Is it possible?
3565
After reading a couple of answers and comments on some SQL questions here, and also hearing that a friend of mine works at a place which has a policy which bans them, I'm wondering if there's anything wrong with using backticks around field names in MySQL.  That is:  SELECT `id`, `name`, `anotherfield` ... -- vs -- SELECT id, name, anotherfield ...
3170
What is the best way to get IDENTITY of inserted row?  I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don't understand the pros and cons attached to each.  Can someone please explain the differences and when I should be using each?
27742
I have process in salesforce in such a way opportunity we can relate this opportunity to this lookup field parent_opportunity__c . Which relates opportunity to other parent opportunity.  I want to write a query parent to child :  select id,(select id from opportunity where parent_opportunity__c!=null) from opportunity where parent_opportunity__c=null   I have worked with different scenarios i cant able to crack it  select id,name,(select id,name from parent_opportunity__r) from opportunity this is showing error and   select id,name,(select id,name from opportunity) from parent_opportunity__c this is also error
405
I have two tables in my database:  NEWS table with columns:   id - the news id  user - the user id of the author)   USERS table with columns:   id - the user id   I want to execute this SQL:   SELECT * FROM news JOIN users ON news.user = user.id    When I get the results in PHP I would like to get associative array and get column names by $row['column-name']. How do I get the news ID and the user ID, having the same column name?
46559
One of my columns is called from. I can't change the name because I didn't make it. Am I allowed to do something like SELECT from FROM TableName or is there a special syntax to avoid the SQL Server being confused?
65829
I have a list of accounts that I would like to perform a LIKE query on. Ideally, my query would be something like:  SELECT id, owner.name FROM Account WHERE name LIKE IN :entityList   Is there any way I can do this?  The issue is that my entity names come from a third party source, which means that small variations in name may be present, i.e     "Bay Ridge apt." VS "Bay Ridge Apartments"   It's hard to predict where the difference in spelling might be, and I was hoping that the LIKE filter might be some magical filter that can figure this out for me and match on a substring (i.e. "Bay Ridge").  The Salesforce guide doesn't include this option in their guide, so it might not be possible to combine a LIKE and an IN. Maybe there's a solution around it?  Maybe there's a way to perform a SOSL query on a list? Something like :     Find {entityList} In Account   I can't seem to find this any where...  Any guidance?  EDIT: It seems that it's not really possible to 'bulkify' SOSL queries. I could have ran a loop, but this would have hit governor limits. Using the LIKE filter with strategic wildcards was key.
55426
I have a heroku postgres add-on database with a user table. However, when I attempt to select * from user, all I get is:    current_user   ----------------  rtsjlhdfptlaqd (1 row)   The table name is definitely user. There is no users table. There are definitely a bunch of users in my app, but I can't seem to list them.   Thoughts?
52560
I am getting "Error System.QueryException: List has no rows for assignment to SObject".   Line 1: Account ac = [select id from Account where name='testaccount' limit 1] Line 2: if(ac != null) {           //do something         }   I got the above error in line 2 if there is no record.   Any help?
16538
In MySQL, how do I get a list of all foreign key constraints pointing to a particular table? a particular column? This is the same thing as , but for MySQL.
34626
the soql in the following code is failing. The error message is: "Compile failure on line 6, column 5: Unexpected token '&lt;'."   Map&lt;Id, String&gt; profileIds = new Map&lt;Id, String&gt;(); profileIds.put('00eee000000xxxx','System Administrator'); profileIds.put('00eee00000yyyyy','YYY Profile'); profileIds.put('00eee00000zzzzz','ZZZ Profile');  List&lt;User&gt; users = [SELECT Id, Name, Email, ProfileId FROM User WHERE NOT(Email like '%@example.com') AND ProfileId NOT IN :profileIds.keySet()]; System.debug(users.size()); for (User usr: users) {     System.debug(usr.id+'    '+usr.Email); }   When I run the Query in SOQL Editor, it says "unexpected token: AND"  SELECT Id, Name, Email, ProfileId FROM User WHERE NOT(Email like '%@example.com') AND  ProfileId NOT IN ('00eee000000xxxx','00eee00000yyyyy','00eee000000zzzz')   When I remove one of the clauses from the where statement, it works. I do not understand whats wrong with the query. I tried wrapping the query with in parenthesis too, but no luck. for example   List&lt;User&gt; users = [SELECT Id, Name, Email, ProfileId FROM User WHERE (NOT(Email like '%@example.com') AND ProfileId NOT IN :profileIds.keySet())];  List&lt;User&gt; users = [SELECT Id, Name, Email, ProfileId FROM User WHERE (NOT(Email like '%@example.com') AND (ProfileId NOT IN :profileIds.keySet()))];
25957
I want to write a function that returns users which have entered a certain value to a custom user field.   Lets say there is a custom birthday field for every user. What would be the best way to get all users with a certain birthday?  I could create a DB query that searches the field_data_field_birthday table and returns the entity_id(s) (which in this case would be the users id(s)) for which the field_birthday_value matches a given value and then load the user(s).   This seems a little bit crude, are there generic functions for this use case available? In the entity API or the field API maybe?
99826
Why my soql query is returning 'RecordTypeId' instead of the fields mentioned in the query?  Here's my query:  SELECT Id, Name, ABC, (SELECT Id, XYZ FROM InnerObject) FROM OuterObj   Note: My query contains a subquery.
12604
I have 2 tables. One (domains) has domain ids, and domain names (dom_id, dom_url).  the other contains actual data, 2 of which columns require a TO and FROM domain names. So I have 2 columns rev_dom_from and rev_dom_for, both of which store the domain name id, from the domains table.  Simple.  Now I need to actually display both domain names on the webpage. I know how to display one or the other, via the LEFT JOIN domains ON reviews.rev_dom_for = domains.dom_url query, and then you echo out the dom_url, which would echo out the domain name in the rev_dom_for column.  But how would I make it echo out the 2nd domain name, in the dom_rev_from column?