Skip to content

Tag: sql

Retrieve rows where Column1 != Multiple Values from Column2

I have 2 Location columns. I need to find a way to show only exceptions, where Location1 != Location2, BUT there are multiple values in Location2 column that can be associated with value in Lcoation1. For example: San Diego in Location1 column can have 4 possible values in Location2 column (North, Central, So…

Postgres: Searching all sub-arrays of an array

I have a Postgres table with a json column, named raw_data, that is structured like this: [{“id”:1234, “name”:”John Doe”, “purchases”:12}, {“id”:1234, “name”:”Jane Doe”, “purchases”:11}] The number of sub-arrays ca…

can’t set a foreign key on oracle sql

Here is my code: and it gave me this error: What is wrong with parenthesis in my code? this only happens when i set foreign key. Note: i am using SQL cmd from Oracle Database 11g Express Edition. I’ve tried making theses tables on MySQL and it worked fine. Answer No “FOREIGN KEY” keyword is …

Count rows between time periods excluding time-overlap

I have a table where it holds some vehicle events, I need to count the number of event occurrences every 5 minutes. Sample : I was able to get the results by the following query : query results : The issue with the above results is that the query excluded Ids (15 and 28) the correct output should be :

How do I conditionally select a unique value in SQL?

I’ve been tasked with returning only rows with unique IDs but returning a row for every ID in SQL. How would I go about this? Logic: For primary row, select where JOB_INDICATOR = ‘P’. If there are multiple rows, then use the record where PRIM_ROLE_IND = ‘Y’. If there are still multiple then select the l…