October 22, 2024
Chicago 12, Melborne City, USA

SQL

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample dat

SQL

MySQL left join produces less optimal query

My users table lists all users: id name 1 alice 2 bob My users_teams table defines which users are in which teams. id team_id user_id 1 100 1 2 100 2 I want to search for users with a certain name, and also know which team they are on. I select the users first, which

Read More
SQL

unbale to get the data from ORDS plsql block if input is an json array of objects

I’m using below PLSQL block within my Oracle ORDS where my current input json body is like below ['123','456'] but i want to change the input json body to below format (unable to decide the logic) [{ "vendorid":123" }] my current working code is like below (for input body [‘123′,’456’]), i’m not understanding how to

Read More
SQL

Get the non-matching rows in SQL

We have two SQL tables and . Now, We have to do a merger of these two table in such a way that, table_1 seq_number which is not present in table_2, map with the tp_no = 0 Like this. We have to create this in SQL table so it could be used further. I am

Read More
SQL

ORA-01031 : Cross Schema Procedure Execution Issue

I have three schemas META, DATA and a Custom schema in an Oracle DB. I’ve declared one simple procedure in META schema. CREATE OR REPLACE PROCEDURE TEST1 ( v_name IN VARCHAR2 ) IS BEGIN DBMS_OUTPUT.PUT_LINE('Hello, ' || v_name); END TEST1; / I haven’t given any grants on DATA or CUSTOM schema for this procedure. When

Read More
SQL

Confusion Encountered When Using arrayJoin Function and GROUP BY Clause in ClickHouse

the first sql SELECT rtx , arrayJoin(['Istanbul', 'Berlin', 'Bobruisk']) AS city FROM ( SELECT 'hi' as rtx ) where city = 'Istanbul' group by rtx, city; the result is rtx city hi Istanbul the next sql SELECT rtx , arrayJoin(['Istanbul', 'Berlin', 'Bobruisk']) AS city FROM ( SELECT 'hi' as rtx ) where city = 'Istanbul'

Read More
SQL

Data lineage – Remove the all comments from [VIEW_DEFINITION] in Azure SQL DW

I need to list the columns and tables that are used in the creation of the view [dimension].[v_dim_customer] . To do this, I query the value of the column [VIEW_DEFINITION] which contains the SQL query for creating the view. SELECT v.TABLE_SCHEMA,v.TABLE_NAME, v.VIEW_DEFINITION FROM INFORMATION_SCHEMA.COLUMNS c JOIN INFORMATION_SCHEMA.VIEWS v ON c.TABLE_NAME = v.TABLE_NAME and c.TABLE_SCHEMA =

Read More
SQL

Does using ORDER BY on an indexed column in a query cause issues if new rows are inserted during query execution

I have a table Users with id, this table has a million records or more. So when fetching data from the table I am using batching with offset & limit to reduce load on my server. My question is if we are executing the below query of fetching the data from the table, simultaneously a

Read More
SQL

Convert 1minutes interval data to 5min,15min,30min,1hour interval in oracle sql

I have a table which contains data of 1minute time interval of a stock. I need to convert the data into 5min,15min,30min,1hour time intervals and group the columns. I have no idea how to convert time intervals. Can anyone help me pls. date open close 27-09-2024 15:25:00 352.85 352.75 27-09-2024 15:26:00 353 351.95 27-09-2024 15:27:00

Read More
SQL

How to flatten a json array string in Redshift

I have a table like this: id stage(varchar) 1 ["a","b"] 2 ["c"] and I need to retrieve the data as the following format: id stage 1 a 1 b 2 c How should I write my SQL in AWS Redshift? You need to sign in to view this answers

Read More
SQL

Why is the syntax “column = NULL” allowed in SQL?

I know this question doesn’t really belong here, because I ask for an explanation and not for a solution to a problem. If there is a better place to ask it, feel free to redirect me. I understand the difference between column IS NULL and column = NULL in SQL, multiple answers such as this

Read More