I am trying to create a new column that counts unique partitions of another column. ColA *NewCol ———— A 1 A 1 A 1 B 2 B 2 C 3 C 3 C 3 I have tried using …
how to use an if statement in update query in Oracle
I wanted to use if statement in Oracle update. Below is the condition that i wanted to achieve and i will not be able to use PL/SQL. I wanted to achieve the below result using update statement. if …
SQL: How to write multiple interactive scripts in one query (insert rows)
Simple question- I just want to learn how to write a query that will insert 2 rows into my table by writing one query, instead of 2 separate ones. My queries work completely fine, I just want to know …
T-SQL – Count unique characters in a variable
Goal: To count # of distinct characters in a variable the fastest way possible. DECLARE @String1 NVARCHAR(4000) = N’1A^’ ; –> output = 3 DECLARE @String2 NVARCHAR(4000) = N’11’ ; –> output = …
Schema Design for a questionnaire with single or multiple choices with no right / wrong answer
Firstly, I went through tens of questions over here related to mine, but couldn’t quite find what I’m looking for, hence asking a seemingly duplicate question again. I have a requirement for a …
constraints foreign key pros
so besides just naming a foreign key, is there any real advantage creating a constraint foreign key instead of a normal foreign key?
Incorrect syntax near the keyword ‘right’
i am very new to SQL, spent hours searching but all the articles point to more or less same Bellow is my code, but honestly not sure what am i doing wrong here. I want to join both tables via ID, keep the id from left and take other parameters from right table user_private_store_items i get Incorrect syntax n…
Assertions in Snowflake
Is there a way to perform assertions in Snowflake? Basically, I’m trying to do a bit of testing/TDD, and I’d like a mechanism similar to assertions in every other language: If the assertion succeeds, it returns true (and/or prints a success message). If the assertion fails, an exception is raised.…
Finding Duplicate Rows in a Table
I am trying to find out how many duplicate records I have in a table. I can use count, but I’m not sure how best to eliminate records where the count is only 1. I can try to order by the count, but I am still not eliminating those with a count of one. Answer you can use having clause
Parse String and Insert Results Into 3 Fields
I have a field in a SQL table that looks like this. It’s literally a file name. I’d need to create 3 new fields and split the string shown above into this. How can I do that? I have this basic SQL that does the select and parsing, but I’m not sure how to do the insert into. I am