Skip to content

Select ans specific value or, if not exists, the minimum one

I’m stuck trying to solve a problem using SQL (MySQL 5.6). Need to get the address which has ID 2 or, if not exists ID 2, the lower ID. For example If a costumerID have an AddressID 2, must get that. If not, must get the minimum AddressID. The output must be like: So far I’ve tried this: but get

Add a Unique ID Number To Duplicate Rows SQL

I have the below table called TestTable and need to update the MsgNum column to have a unique number ordered by the date column but grouped by the JobNum. JobNum | MsgNum | Date 320 | 0 | …

Group By and Groups of Groups in MS Access

I am trying to write a query in MS Access using group by that results in the count of two groups and then the count of the remaining groups combined. So if I have a field color and 18 items and I do …

How to group and order rows with different date values in SQL

I have a result like this: Query is pretty simple: I need to group them, get sum of amount and order by date. Notice that date values are not the same. I can’t group results because of this. Important thing is i need to order by Date column. This is the result i want: I’m trying this code but sql