I want to get the Company name and all the products they purchased in a single SQL query. The database used is the Northwind sample database. The relations between these columns and dbs’ tables look …
Tag: sql-server
Group by to include case statement inside SQL statement
I have a table which stores purchase info from sellers and table contains rating to every purchase out of 5 stars. I want to have output Group By sellers and Each sellers good(Above 3) and bad(Below 4)…
List the films in which ‘Harrison Ford’ has appeared
Why is the answer to this question incorrect? Database Question: List the films in which ‘Harrison Ford’ has appeared My answer: Answer After correcting were -> where and removing the trailing X the syntax and result where correct. Error message indicated it was using MariaDB
Join three selects into one
I’m using SQL Server 13.0.5102.14. I have these three selects: declare @prodID int = 1; declare @lotAI varchar(4) = ’10’; select cod.Serial as ItemNO, varData.Value as Lot, pro….
Query is taking a long time to execute [closed]
The query is taking too much time to execute. Ots comparing some condition and then fetching data accordingly. Please guide me why its happening. DECLARE @Rowcountcnzg int = 0; DECLARE @countcnzg …
How to select duplicate records for a column having Data/NULL values in other columns?
I have a table in SQL server with 2.5 M records and I want to select the unique records as in image below. Can someone help me write a select query for this? Original table and requested data:
Incorrect next near when use iif with set in sql Servr
When I use a statement and set in same query, we get Incorrect syntax near ” DECLARE @Enter int DECLARE @Month INT DECLARE @year INT DECLARE @Delayed INT = NULL DECLARE @…
Merge every 2 consecutive records into 1
I have a pre-processed table which I want to group every pair into one record containing data from fields of both records. |——————-|—–|—-| |Timestamp |Event|User| |———-…
SQL determine if more than one column on a given row has the same value
I have a SQL Server table that includes 9 columns used to indicated what things to include or exclude in part of the UI. Each column can have the value ‘A’, ‘X’, or blank. Each row should have at most 1 ‘A’ in any of the columns. Due to an error many columns have multiple &…
How to prevent logical duplicates in a unary one to many SQL relationship table
In a non directional unary relationship what would be the best option to prevent logical duplicates? E.G. Main table ID — 1 2 Relational table ID1 ID2 ———– 1 2 2 1 Entry two …