Skip to content

Tag: sql

UPDATE RECORD 2 FIRST LATTER IN MYSQL [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 11 months ago. Improve this question How…

SQL – get rid of the nested aggregate select

There is a table Payment, which for example tracks the amount of money user puts into account, simplified as What is need is to receive a table with balance before payment moment, eg: Currently the select statement looks something like How can I rewrite this select to get rid of the nested aggregate selection…

How to LEFT JOIN with multiple cases

Assuming I have these two tables like: Table: tab1 valA valB valC valD 1 11 111 A 2 11 333 A 3 44 444 B 3 66 666 D Table: tab2 val1 val2 val3 val4 1 11 111 A 1 22 222 A 2 44 333 B 3 55 555 A 3 66 666 D I have 3 cases that

SQL Finding Dupe Names with Distinct ID

I have a list of customers, and a bunch of them are duplicates (‘Acme Inc’, ‘Acme, Inc’, ‘Acme Inc.’, ‘Acme, Inc.’) They all have different IDs. BUT, each ID also has multiple addresses. Something like… I have a function that normalizes the name so the fir…

SQL ROLLUP with COALESCE

The data: The query: The output I get is like this: It gives null every individual brand item not grouped, and I want the last null to be ‘Grand Total’ not ‘Monthly Total’. I tried putting PurchaseDate or Brand column in and out the ROLLUP but it doesn’t seem to work for the Bran…

How to use Left Join in subquery SQL Server?

I am trying to use left join in subquery in SQL Server. My query looks fine to me but it gives syntax error. This is my query: This is the error I’m getting: This is my table structure: Answer As @Chris mentioned, the query is bit incomplete. I guess you are trying to do something like this: This query …