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

How to fetch parent data and all it's children, then aggregate to array?

Postgres: v12 Link to test: https://www.db-fiddle.com/f/pfnFVhFq1QTxjas6BB4sZv/0 There are transactions table and logs table. logs are linked to transactions by transaction_id. I need to query logs by address, join it with transactions, aggregate logs to array, LIMIT transactions (example is LIMIT 2) and FETCH ALL LOGS that were in that transaction (but query only by one

Read More
SQL

Sqlite union with non existing table

I have an application where tables are dynamically created, while reading data we Union All the data from various tables and show the results, but issue comes when a table is not existing.. Is there a better way to write this query so that it doesnt fail when a table doesnt exists.. SELECT * FROM

Read More
SQL

How to achieve MySQL transaction with complicated computation?

For example, here’s a table with 2 columns called USER_ID, MY_COLUMN. I want to change the MY_COLUMN for a single user specified by USER_ID. If the modification is very naive/simple, say MY_COLUMN is an integer and we only want to increment it by 1, we can achieve this by a simple UPDATE ... SET ...

Read More
SQL

Use init SQL script in C# WPF apps

I’ve got a WPF application and i want to apply some init sql script in order to full some table. In my all project solution i’ve got one project for the application and one SQLProject to make compare when i modify the tables. i’ve put my sql script in the SQLProject folder, but how can

Read More
SQL

Rows matching conditions in a directly related table or another, related indirectly

Suppose three tables: create table table_a( id int generated by default as identity primary key); create table table_c( id int generated by default as identity primary key , active boolean); create table table_b( id int generated by default as identity primary key , active boolean , table_a_id int references table_a(id) , table_c_id int references table_c(id));

Read More
SQL

Using SQL in an Excel workbooks exhibits strange behaviour until the device is rebooted

I have a macro that runs a a number of different SQL statements. I use the same macro each day. The 1st step is I update the Pending worksheet. The 2nd step is to identify new contracts. New contracts are identified by a SQL statement that compares the Pending worksheet to the History worksheet. Anything

Read More
SQL

SQL table Alias

I have the following SQL statement where the Company table is joined 3 times. There is a CompanyName column in the Company table How do I tell my c# code which alias to read? reader["ex.CompanyName"] does not work Select * from Shipments sh inner join Company cn on cn.CompanyId = sh.ConsigneeID inner join Company ex

Read More
SQL

Left outer join from more tables with dates

A is the main table, with a unique ID. B, C and D are tables containing this ID and Dates and other infos. I have to create a list: A.ID, A.info, a DATE existing in B, C OR D and the other info from B, C and D. Example: A ID_A...infoA and other 1......Tom B

Read More
SQL

Select rows with at least one non-zero value

I have a table with 20+ columns and some rows would only have 0s for all the column. Is there a way to filter out rows where all the columns have 0? I could use select * from table where concat(col1, col2, col3) != '000' but I don’t want to write 20+ zeroes in my

Read More
SQL

Query to get last position by User

I have the following table CREATE TABLE [dbo].[PRC_PosizioniWalkers] ( [ID] [int] IDENTITY(1,1) NOT NULL, [idWalker] [int] NOT NULL, [username] [nvarchar](200) NOT NULL, [data] [datetime] NULL, [Latitudine] [nvarchar](50) NOT NULL, [Longitudine] [nvarchar](50) NOT NULL, CONSTRAINT [PK_PRC_PosizioniWalkers] PRIMARY KEY CLUSTERED ([ID] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =

Read More