Category "sql"

SPARK SQL create table does not show / read all columns as expected

I am trying to create table in spark sql by providing the schema and giving the location. However when i run select on the table, i see only half the columns. (

How is a binary/bytes column sorted in sql?

The following query sorts a binary column in BigQuery: with tbl as ( select B'123' as col union all select B'234' ) select * from tbl order by col; ----------

How do I write a query to find highest earning day per quarter?

I need to write a sql code to pull the single, highest-earning day for a certain brand of each quarter of 2018. I have the following but it does not pull a sing

I'm trying to join 2 tables that don't have same columns and using case select. Is this possible?

select case when code = number_1 then number_1=code when count(code)>=count(number_1) then number_1 = sum(code)

PostgreSQL 12.2 with Sequelize 6.3 - UPSERT a array of data and want ON CONFLIT DO UPDATE to merge current existing JSONB and EXCLUDED JSONB

I'm currently using this query to insert or update my array of data when retrieving my list : try { const query = `INSERT INTO "Tables" ("id","tomerge

SQL Query Find sums from one column for two different columns

I have a Table with Debit Accounts, Credit Accounts and Amount of Transactions between them. I need to take every Account(Which might be debit sometimes and cre

Error: 'duplicate key value violates unique constraint' even when checking with 'where not in'

I get the error: 'duplicate key value violates unique constraint' even when checking if the primary key is already in the table in which I want to insert. I ha

Create a procedure to fill a new table

I am new to PostgreSQL and am struggling with the creation of a procedure to save the data in a new table. This is how the empty table is created CREATE TABLE e

How to reference the default schema in liquibase preCondition sqlCheck

Posting here in case it helps someone. TLDR: ${database.defaultSchemaName} within sqlCheck to access default schema name I wanted my database changeset to firs

Oracle db - remove ,, from email address

I'm running below code and getting below results but I want to remove ,, and after ,, texts from email address and that email address should show in UPPER(PT_PA

Remove duplicate entries from string array column of postgres

I have a PostgreSQL table where there is column which has array of strings. The row have some unique array strings or some have duplicate strings also. I want t

Reverse EBCDIC sorts numbers before letters in ROW_NUMBER function

So I do have following SQL select SELECT FOO.*, ROW_NUMBER() OVER (ORDER BY KEY ASC) AS ROW_NUMBER FROM FOO Key is of the type VARCHAR(12). I wonder why the h

Assert Text Error, AssertionError: No text to speak

I'm working on a project that uses voice assistant to query information stored in my sql database but I keep getting this error. The voice assistant is able to

Results of group by null values are lost

I have table which has productId and productVariantId columns. |id |userId|productId|productVariantId| ---------------------------------------- |1 |1

Updating a table from data in another table and multiple matches

First time posting here, normally I am able to find an answer to my questions by searching but not this time... I have a table T1 with 2 sets of coordinates (st

SQL: Use RegEx to return multiple substrings of a specified string in column

I am querying metadata on Snowflake which contains a column of queries: select query_name from metadata query_name SELECT * FROM SYSIBM.SQLCOLUMNS SELECT * FR

Is there a way to make a "natural join" with a table having a foreign key on another table?

This is just a dummy example. In reality I have a foreign key which references a lot of more columns. That why I'm trying replace the normal join with a "natura

Need to get appropriate/expected row number in Oracle PLSQL

Getting the following output when i use the below query SELECT P.RefNum ,Ian.ID ,Ian.Date ,Igl.Name ,Ian.Comments ,ROW_NUMBER() OVER (

Add a column with a default value to an existing table in postgresql

Question: Is there a postgres query to add a new column to an existing table and to automatically populate that column for all rows of the table with a certain

#1558 - Column count of mysql.proc is wrong. Expected 21, found 20. Please use mysql_upgrade to fix this error

I got this message when I try to run query on XAMPP in macOS #1558 - Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100108, n