I have an issue with a query where I want to accumulate values and then group them PS: This is a simplified example CREATE TABLE [dbo].[OWNER]( [personId] [int] NULL, [ownerId] [int] NULL, …
POSTGRESQL. Insert or update on table violates foreign key constraint
I am new in Posgresql. I have 5 tables and I am trying to INSERT properties to tables. When I tried to Insert 2nd time, I have this error in ‘pgadmin’. ERROR: insert or update on table “question” …
Querying SQL column varchar6 containing numbers with a between statement
The table has a column that is type varchar6 containing 6 numbers between 000000 to 999999, or is empty. No matter what values you give the various variables for this column SEQ, it keeps returning no results but no syntax errors. I suspect you can’t find anything in SQL if you do a between with two var…
Show TOP 1 considering where condition if present -SQL query
I have a case where I am using a OUTER APPLY query as below OUTER APPLY ( SELECT TOP 1 CUSTOMER_CATEGORY FROM [UX_VW_CUSTOMER_DETAILS] UVFS WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID ) …
pyscopg2: Is it possible to dynamically add %s in loop
I am trying to create a method in python insert records into a table passing in a list of column names, and an associated list of records. I was able to set it up where the column names populated dynamically via a for loop, but I can’t figure out how to do the same thing with values because the psycopg2…
Mark existing rows as duplicates when selecting with left join in T-SQL
I am trying to do a LEFT JOIN to merge a table and view and the right table has duplicate items(usernames). I want to keep them but add another column to mark them as isDuplicate=’TRUE’. I wanted to use CASE WHEN EXISTS but can’t get it to work correctly, it produces wrong results: Ideally I…
Data Type for Lists
I’m creating a table and one of the requirements is that the only option that can be entered are QLD, NSW, VIC, SA, WA, NT and ACT (Australian states). What is this datatype and how is written in SQL, …
Count of Value column with case when and group by
Table: Date Id Value 2019-02-09 a1 ab 2019-01-12 a2 cd 2019-12-12 a1 ab 2017-07-23 a1 ab 2018-12-09 …
How to type Degree symbol (°) in Azure SQL data warehouse
I have data source like this: 1°18’19.74″N But when I insert it to Azure data warehouse it look like this: 1�18’19.74″N
PostgreSQL Why sequence increases only once with two “nextval”
I am implementing a board with a comment function. I created a table like this with nextval create table tr_board ( b_id varchar(20) not null default nextval(‘seq_board’), title varchar(256)…