I have a table with following schema: Column Type Description user_id INT A unique identifier for a student. session_id INT A unique identifier for a course. is_sigtrack CHAR …
Tag: sql
UNION two SELECT queries but result set is smaller than one of them
In a SQL Server statement there is SELECT id, book, acnt, prod, category from Table1 UNION SELECT id, book, acnt, prod, category from Table2 The first …
SQL Query for multiple joined tables
I am querying against a SQL Server database and I’ve been struggling to get the result set I want. I feel like it is possible but I’m just unable to do it. Here is how the DB is layed out. I’d like to return a result set that looks like this: I’ve unsuccessfully tried using CTE’s…
BigQuery SQL : Dynamically Concat all rows in column by key
I have a table like this: Customer Plan/Date A free (20/01/2020-01/02/2020) A starter (01/02/2020-01/03/2020) A full (01/03/2020) B trial (02/03/2020-05/04/…
Impala incompatible return types in case when statement
I am running an Impala query and try to use a case when statement: It complains This however works fine: As the error message indicates, PRTCTN_ALLCTD_VL is of type decimal(38,10). Any advice is appreciated Answer This is a curious problem, one that I would not expect. A case expression returns a single type …
Using declared variables in SQL Oracle query FOR LOOP
I’m attempting to write a query script where I declare a variable and then use them in a select statement in Oracle SQL. Basically script should check if parent tables’ entries are used in referenced table or not. if not –> delete the entry from REF table. So far I have this So far LOG_MS…
How to remove While loop inside stored procedure in MS SQL Server? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have a stored procedure with a cursor inside for the logic which is taking…
Need to match a field with another that has commas on it’ s value
I would like to match the field values of “FORMULATION” from TABLE 1 to “C_TEST_ARTICLE” from table 2, that has mutiple of these formulation sepparated by commas. Table 1: +——–…
SQL – Delete random rows where sum is equal to given number
I want to get some random rows from the given table where the sum is 250(this can be changed). I don`t need to 100% accurate but can be approximate. Like for 250 (1,5,7) Note:- My table has huge data. Answer For any specific numbers, you can return the closest sum using logic with joins. For instance for 3 nu…
Insert row with uniqueidentifier
This is a snippet from a stored proc that creates a database. We have a table with uniqueidentifier PK. I’m trying to insert a row with an empty guid as the PK: The error messages are Can’t see what’s wrong with the VALUES clause but I guess it has something to do with the final quote, altho…