Category "sql"

In SQL, how do I filter a parent with its child records if either satisfies a condition

I have the following table as example. I want to retrieve only the records where the ScheduleDate is smaller than 2022-01-03 (Jan 3, 2022) for either the parent

How to Join two tables and update a column?

I have two tables as below TableA TableB ID1 ID2 ID1 ID3 1 X 1 X 2 NULL 2 A 3 (NULL) 3

How to get tally of unique words using only SQL?

How do you get a list of all unique words and their frequencies ("tally") in one text column of one table of an SQL database? An answer for any SQL dialect in w

SQL Developer Language won't change

I have an issue with SQL developer where the GUI language won't change as it shows here Now I have tried the solutions where I added the following to sqldevel

SQL Group/Orderby

I have a set of records in a db table like this. The thing that logically links these records is guid1 and guid2 but not all records in the table have a full re

MySQL, count values by key

I need to count values on a table accordingly with their presence or missing. With a clear example consider a table with 2 field: +-------+---------+ | K |

MySQL pagination with limit returns the same values

I'm trying to do pagination, but the SQL query returns the same values on different pages. I show them the queries and the results, and it shows that there are

SQL Server 2017 undetected deadlock issue

The problem is: BEGIN TRANSACTION SELECT TOP 1 q.* ) FROM [QTable] q WITH(UPDLOCK) WHERE <some condition> ORDER BY <some columns&

SQL: select all depending nodes from a list of parent

let's take a table called users like this id name ... path 22 John ... 2/8/11/22/ 23 Mark ... 1/3/9/15/21/23/ where the path rapresents the hierarchy parent-c

MySQL Create View with Sequence Numbers for Each Group

I've seen a similar solution on this site but it's not usable in a view due to variable use limitations: Generating Sequence for Each Group in MySQL A table s

Oracle Pivot with 3 Tables

I am using a PIVOT to combine two rows with the same ID into a single row: SELECT B1_ALT_ID, B1_CHECKLIST_1, B1_CHECKLIST_2 FROM B1PERMIT A JOIN BCHCKBOX B ON A

join produces wrong results though the joining columns are of same datatype. Right results are after casting them to different datatype

I have an interesting problem to find the root cause. Inner join 2 tables on 2 columns, but the results are not expected. The data types for both columns are th

Where Condition on google auto complete address

I have a home search table with have a city column which can have multiple cities like "Avignon, France|Nantes, France|". Addresses are "|" separated. There's a

Selecting values in a partition where a condition is met (Teradata SQL)

I have table that is in the following format: Number Departing Arriving Departure Time Removal Indicator 1 Miami Dallas 1 PM N 1 Chicago Dallas 3 PM Y 1 Dallas

What is the best way to get a decimal or a float result when dividing two numbers in SQL [duplicate]

I declared a variable @avgMis as a decimal(2,2) in SQL Server. Then I tried to divide two integers, expecting a decimal value. Instead my answ

How to convert this timestamp in PLSQL?

Using PL/SQL I have a TIMESTAMP(6) like this: 21-APR-22 02.25.00.000000 PM. I need to convert it to format YYYY-MM-DD HH24:MI:SS (EX: 2022-04-21 14:25:00). EDIT

Find dates with lower revenue than yesterday

I'm fairly new to BQ SQL and am stuck on a query regarding dates. I have a table that consists of customer_id (int), date_purchase (date), sales (int). The quer

Condition in creating view - liquibase xml

I want to make some view but with condition in my fourth column. CONDITION: If epr.j_id is not null then fill lj.id BUT WHEN epr.j_id is null then fill 'NONE'

Rspec and SQL: Index 0 is out of range

I am trying to run my code and I get the following error: Failure/Error: Bookmark.new(id: res[0]['id'], title: res[0]['title'], url: res[0]['url']) IndexError:

How do I extract a date (dd-mm-yy) from a timestamp with timezone (timestamptz) in postgresql

My date column "timestamp" is currently listed as: 2020-11-16 20:27:38.033 +0000 It's formatted as timestamptz and I've tried every search on here and google to