I have a query that inserts data from another table, into an empty table (the table is cleared once a day, and new data is put in once a day). Currently it looks like this: INSERT INTO new (…
create column for unread notifications in union query
I’m trying to distinguish two unioned selects. I have two tables: notification and read_notification. notification table: id title body —————– read_notification table: id user_id …
How to make sure only one column is not null in postgresql table
I’m trying to setup a table and add some constraints to it. I was planning on using partial indexes to add constraints to create some composite keys, but ran into the problem of handling NULL values. …
Pattern matching techniques in SQL to correctly match a sting to a keyword but not getting the right results
I have a table (dbo.Library) where I have build a library of keywords that are associated with different titles and persona in a company. See below: CREATE TABLE dbo.Library (ID INT IDENTITY(1,1), …
SQL – return a value referenced by initial value from same table
I’m sure this has been asked before, but I can’t seem to find any questions that help. Here’s an example of a table: ID Name Parent ID ————————— 1 Ice cream 3 2 …
How do I find a duplicate in SQL
I have a query that selects 3 columns. Each row row should be a unique combination of county, city,and zip. However, I have reason to believe I’m getting a duplicate somewhere. How do I find the …
How do you get the size of the gap from LEAD or LAG?
In my table, I have messages grouped by threads. Using LEAD, I can get the next message within a thread… [ThreadNextMessageId] = LEAD(gm.GroupMessageId, 1) OVER(PARTITION BY gm.ThreadId ORDER BY gm….
Oracle query to find one to many relationship in same table
I am new to query writing and need help to prepare a query in oracle . Here is the scenario, basically i need to find all the products where same product (col1) assigned to multiple codes (col2). …
SQL – Aggregate Functions and Group By
MyView: JobId, ClientName, ClientAddress, Cost Example data within MyView: 1, John, 23 road, 25 1, John, 23 road, 20 1, John, 23 road, 5 2, James, 6 road, 10 2, James, 6 road, 4 I want to SUM the …
I don’t want NULL and want to have values in one row
create table employee( empid int, name varchar(5), salarytype varchar(10), salary int ) insert into employee values (1, ‘A’ ,’Fixed’, 500); insert into employee values (1, ‘A’ ,’…