I’m stuck at the query where I need to concat IDs of the table. And from that group of IDs, I need to fetch that rows in sub query. But when I try to do so, MySQL consider group_concat() as a string. …
Multiple batches in a SQL transaction
I want to create several stored procedures (or user-defined functions) within a transaction. CREATE PROCEDURE statement must be the only statement in the batch, so I have to use following template: …
How to append values of an array to an SQL statement in Javascript
let todo = [1, 2, 3, 4, 5, 6, 7, 8]; var stmt = “SELECT * FROM MY_USERS WHERE USER_ID = ?”; connection.query(stmt, todo, function(err, row) { }); connection.release(); I would like to SELECT * …
How to add “or” in SQL select query?
I am creating a report to get customer wise incoming payment in a particular period. Payment can be received through Cheques, Direct Bank Transfers, Cash. This payments saved in the database in a …
how to rewrite query to put data-modifying CTE at top level
I’m trying to write a query for Postgres to insert a row into one table which as a side-effect may insert a row into a second table (due to the first table having a foreign key constraint on the …
Group By and Count the total number of same status value
I have 2 tables, Order and Store. And here are some of the fields from the table I need. Order table OrderId StoreId SystemOrderStatus 1 1 Received 2 1 Sent …
How to insert records to temptable which has ;with command in sql?
I have created a temp table which I want to fill with records. Here is my query: create table #temp(companysitetankid int, [SourceGradeName] varchar(50), SiteCode varchar(50)); ;with cst as ( …
NHibernate IN Expression / Restrictions Hitting 2100 Parameter Limit SQL Server
Is there a way to force NHibernate to run a query without executing it as a parameterized query. Basically I’m running into an issue where I am hitting SQL Server’s 2100 parameter limit. I’m hitting a limit because of an “IN” restriction on my query. For reasons I won’t get…
SQL JOIN with 2 aggregates returning incorrect results
I am trying to join 3 different tables to get how many Home Runs a player has in his career along with how many Awards they have recieved. However, I’m getting incorrect results: Peoples PlayerId …
Using an Inner Join and returning only 1 record per match on the left
I don’t know why I’m not able to figure this out ATM. Here’s a very contrived example. create table Dog ( [Name] varchar(10), [BreedId] int ); create table Breed ( [BreedId] int, [Name] …