I am having a hard time understanding why the following query is not working?  select id,sold_dealer_id from myi_corporate where sold_dealer_id != 36;  When I do the following I am getting the result  select id,sold_dealer_id from myi_corporate where sold_dealer_id = 36;  However for != I am not getting the opposite results.   I am returning to psql after a long time after using MongoDB and might have forgotten the basics. Any suggestion is much appreciated
123269
Inspired by a StackOverflow question ().  Is there a DBMS that actually supports the = NULL syntax?
89546
I'm trying to create a new field based in another (sum field)  SELECT sum(price) AS old_price,    old_price+100 AS total_price FROM sales   This returns Unknown column 'old_price' in 'field list'  sum is just a example, my real issue is to use with a select inside this field  What am I doing wrong?  Thanks.  --edit I've used variables to reuse the alias, updated code:  SELECT @old_price := sum(price) AS old_price,    @old_price+100 AS total_price FROM sales   If you think that it is not a good practice, tell me.
45618
I was browsing through the questions and noticed this:  SELECT prodid, issue FROM Sales  WHERE custid = @custid  AND datesold = SELECT MAX(datesold)               FROM Sales s               WHERE s.prodid = Sales.prodid                   AND s.issue = Sales.issue                   AND s.custid = @custid   I was wondering what the "@" does in front of custID?  Is it just a way of referencing the custID from the table being selected?
94559
I was just told that I can't run another query:   Too many queries are running, you may only run 2 queries at a time  But I was only running one. Why did it tell  me this? Does running one for Stack Overflow count as 2?
113237
I am running a soql query to obtain the value of a specific field from a custom object and it is returning the ID of the record on the visualforce page instead of the field value that I need it to return, the specific query I am having issues with is the Names query on the very bottom. If anyone has any ideas why it's returning the ID of the record instead of the specific field value please let me know.   patient_name__c is the field name that I need to obtain the value from and lead__c is a custom object that we have created.       public without sharing class LeadAlertController {     public integer leads {get;set;}     public integer overleads {get;set;}     public List&lt;lead__c&gt; Names {get;set;}         public LeadAlertController() {         leads = [select count() from lead__c where lead_status__c=:'Not Attempted'];         overleads=[select count() from lead__c where lead_status__c=:'Not Attempted' AND x10MinAlert__c=:true];         Names = [select patient_name__c from lead__c where lead_status__c=:'Not Attempted'];       } }   Here is my VF Page  &lt;apex:page controller="LeadAlertController" showHeader="false" sidebar="false" standardStylesheets="false"&gt; &lt;!-- Begin Default Content REMOVE THIS --&gt; &lt;meta http-equiv="refresh" content="10"/&gt; &lt;style&gt; td{     border: 1px ;     border-style: solid; } &lt;/style&gt; &lt;table align="center" style="width:100%;border:1px solid"&gt;     &lt;tr&gt;         &lt;td align="center"&gt;             &lt;h3&gt;Number of Hot Leads&lt;/h3&gt;         &lt;/td&gt;         &lt;td align="center"&gt;             &lt;h3&gt;Number of Hot Leads Over 10 Minutes&lt;/h3&gt;         &lt;/td&gt;          &lt;td align="center"&gt;             &lt;h3&gt;List of Names&lt;/h3&gt;         &lt;/td&gt;     &lt;/tr&gt;     &lt;tr&gt;         &lt;td align="center"&gt;             &lt;h1&gt;{!Leads}&lt;/h1&gt;         &lt;/td&gt;         &lt;td align="center"&gt;             &lt;h1&gt;{!OverLeads}&lt;/h1&gt;         &lt;/td&gt;          &lt;td align="center"&gt;             &lt;h1&gt;{!Names}&lt;/h1&gt;         &lt;/td&gt;     &lt;/tr&gt; &lt;/table&gt;  &lt;apex:outputPanel rendered="{!if(OverLeads&gt;0,true,false)}"&gt;     &lt;audio src="/resource/alert" type="audio/mp3" autoPlay="true"&gt;     &lt;/audio&gt; &lt;/apex:outputPanel&gt;
14134
I had to write a simple query where I go looking for people's name that start with a B or a D :   SELECT s.name  FROM spelers s  WHERE s.name LIKE 'B%' OR s.name LIKE 'D%' ORDER BY 1   I was wondering if there is a way to rewrite this to become more performant. So I can avoid or and / or like?
9915
Query 1:  select count(UserID) from users where UserID IN (select UserID from otherTable)   Returns: 178  Query 2:: (simply changed IN to NOT IN)  select count(UserID) from users where UserID NOT IN (select UserID from otherTable)   Returns: 0  Query 3: (remove the IN-clause completely)  select count(UserID) from users   Returns: 1047123 (over a million)  What? I can't... Even...   The only explanation I have is my database in inconsistent/corrupted, I have to run DBCC CHECKDB or something.  PS. UserID is a primary key, so - no dupes.
110579
I've been working with databases for the last few years and I'd like to think that I've gotten fairly competent with using them. However I was reading recently about Joel's  and I realised that even though I can write a query to get pretty much anything I want out of a database, I have no idea how the database actually interprets the query. Does anyone know of any good articles or books that explain how databases work internally?  Some specific things I'm interested in are:   What does a database actually do to find out what matches a select statement? How does a database interpret a join differently to a query with several "where key1 = key2" statements? How does the database store all its memory? How are indexes stored?
1105
I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries.  An example would get to all entities that has a date field where the value is null or after today.  Am I missing something or some trick or is this simply not supported?
13495
I have 2 tables: Employees, attendanceIn   When I query using LEFT JOIN   SELECT employees.eno,employees.name,employees.dept,attendanceIn.attIn FROM `employees`  LEFT JOIN attendanceIn ON employees.eno = attendanceIn.eno WHERE date(attIn) like '2016-07-02%'   What I got is,     Whats wrong with my Query? How do I get my Expected result?
71622
I need to do a join with a table/result-set/whatever that has the integers n to m inclusive. Is there a trivial way to get that without just building the table?  (BTW what would that type of construct be called, a "Meta query"?)  m-n is bounded to something reasonable ( &lt; 1000's)
117796
I'm trying to write a query which will return a boolean value if there exists any user which has this specific role.  For example is there any user hwo's role is 'role1'  This is how far i got   SELECT CASE WHEN EXISTS  (SELECT --'Here i don't know how to select all user's which have a specific role'--    ) GO   And if it's possible to check user's from only one database .
3723
I'm trying to perform the following multilevel relationship query.   SELECT ID, SystemModstamp, Product__r.Catalog__r.Active__c  FROM Journal__c      WHERE SystemModstamp &gt; 2013-10-02T00:00:00.000+0000  AND SystemModstamp &lt; 2013-10-05T00:00:00.000+0000    In the Product__r.Catalog__r.Active__c column I'm getting a value of [object Object] for every single record. I can substitute any field name from the Catalog__c object and get the same response. Does anyone know why this is happening or how to get the field's actual value?
89157
The following query will display all Dewey Decimal numbers that have been duplicated in the "book" table:  SELECT dewey_number,   COUNT(dewey_number) AS NumOccurrences FROM book GROUP BY dewey_number HAVING ( COUNT(dewey_number) &gt; 1 )   However, what I'd like to do is have my query display the name of the authors associated with the duplicated entry (the "book" table and "author" table are connected by "author_id").  In other words, the query above would yield the following:  dewey_number | NumOccurrences ------------------------------ 5000         | 2 9090         | 3   What I'd like the results to display is something similar to the following:  author_last_name | dewey_number | NumOccurrences ------------------------------------------------- Smith            | 5000         | 2 Jones            | 5000         | 2 Jackson          | 9090         | 3 Johnson          | 9090         | 3 Jeffers          | 9090         | 3   Any help you can provide is greatly appreciated.  And, in case it comes into play, I'm using a Postgresql DB.  UPDATE: Please note that "author_last_name" is not in the "book" table.
49893
Found the following in an Oracle-based application that we're migrating (generalized):  SELECT     Table1.Category1,     Table1.Category2,     count(*) as Total,     count(Tab2.Stat) AS Stat FROM Table1, Table2 WHERE (Table1.PrimaryKey = Table2.ForeignKey(+)) GROUP BY Table1.Category1, Table1.Category2   What does (+) do in a WHERE clause? I've never seen it used like that before.
1681
When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE?  Without any special operators, LIKE and = are the same, right?
40938
After I posted this question, I found a similar post that seemed to answer it: . I'll leave this in place for now, as I am not sure how to mark my own question as a duplicate  In attempting to debug a SOQL query error, I encountered a strange behavior with Database.query and bind variables. Specifically, when I run this code:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } Database.query(userQuery);   the Database.query statement executes with no errors, despite the fact that the variable firstNames does not exist in its context. However, when I add an else clause:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } else {     List&lt;String&gt; firstNames; } Database.query(userQuery);   I receive a null object reference exception. It seems like Salesforce is checking to see if the variable is only declared once beforehand and, if so, uses its value in the context it was declared. This seems strange to me, so I was wondering if anybody here has any insight into what is going on under the hood.