I have a database that every transactions get a alphanumeric ID. By when I write my query and use Order by it give me a wrong sequence. For example: TRN_ID TRNDTE 000002DAAW 2020-09-12 03:45:24 …
Tag: sql
SQL Subquery to handle duplicates
So I am joining to tables, however the table I want to left join has duplicate values for the matching field. I am trying to create a subquery so that when there are duplicates the column value is assigned ‘Duplicate’ and when there isn’t then it takes the value of the join. Here is simplifi…
Use rownum to indicate what rows I have pulled back
I have table of people, with firstname and lastname. firstname lastname a a b b c c d d e e f f g g h h i i j j I want to query from a specific point. For example. SELECT FIRSTNAME, …
Rolling Multiple Rows into a Single Row Based on Matching Data in SQL Server
I have a table in SQL Server with the following layout and some sample data: Is it possible to consolidate like ReferenceNumber rows into a single row, so: I’ve tried: which outputs: Any help would be greatly appreciated. Thanks Answer Assuming this is for small (ish) amount of data, you can correlate t…
MySQL 5.7 – getting latest entry(s) from specific combination of columns
Hello dear MySQL users! i try to solf this since a while but everything i tried does not seem to work. I’m sorry if somewhere is already an answer for that but i know know how to search for. Its not so easy to explain in words so i use this table (called tbl ) to explain it: ID SerNo
Dynamic query to find all the table DML activity in all the table oracle
Hi I need to search the DML activity of specified list of tables in a schema single query since it is time consuming and hard to run individual queries ,so i am trying to prepare a dynamic sql to fetch max(ora_rowscn),SCN_TO_TIMESTAMP(max(ora_rowscn)) from all the tables so that i can use a filter and select …
SQL query to get subtotal on the last row of bill number
I have written the following SQL query which gives the result not in a way I desire. The only change I want is that, I don’t want to repeat the subtotal on every single line, which is what my query is …
Are SQL Server sequences guaranteed to always generate unique values even if called simultaneously from multiple connections?
This is a follow-up question to: Are SQL Server sequences thread safe? I have two separate stored procedures that are calling the same sequence. The stored procedures are launched “in parallel” from an SSIS package. There is no synchronization of any kind between the two stored procedures (other t…
How to sample from different values in a column but only return records that are unique from another column?
I am struggling with a sampling issue using Teradata Below is the format of the data I would ideally like to return a sample number for each entry in Group but with only unique values from ID. Below is the current query I produced but this returns duplicates for ID Answer
How to use only one query (no sub query) to get the rows which mach the requirement?
I need some suggestions for my case. First, I have a table (T1) like this: I want to have a table like this: The issue is, if I can use only one query (without any sub query), what I can do? I tried like this: Select * case when Flag = 0 then ‘F’ when Flag = 1 then ‘T’