7,728 questions
0
votes
0
answers
72
views
Scroll fails while using order by string column in manticore
I’m using Manticore Search 14.1.0 (Docker image manticoresearch/manticore:latest) on Ubuntu 20.04.6 LTS. I rely on cursor-style pagination with OPTION scroll, but when the sort clause includes a ...
5
votes
4
answers
247
views
Sort aggregated query results by two methods simultaneously
I need to sort a query's results by two methods at the same time.
I want the first 3 records (returned) to be based on their prevalence in another table
And then I want the rest of the results sorted ...
-2
votes
1
answer
74
views
MySQL order by id but prioritize an empty value of a certain column
Mainly, I want to order the ids in descending direction but also, how can I sort parent product/items (the ones with empty ean) first and their child rows below them?
Here's an example data from the ...
4
votes
2
answers
159
views
Why does the sort method used by Postgres change from "top-N" to "external merge" when FOR UPDATE is added?
I have a table in Postgres (14) that is used like a queue with FOR UPDATE SKIP LOCKED queries. It was missing an index, but since any rows are usually processed quickly that never became a problem. ...
4
votes
1
answer
171
views
Cursor pagination with conditional sorting
I need to implement keyset pagination (sometimes referenced as cursor-based or seek method) in Postgres with the following ordering rules:
Rows where group_name = :priorityGroup come first (:...
0
votes
2
answers
113
views
How to pick the latest record with GROUP BY userId
In my application I want to find the latest duty of each user from 'StaffDuty' table using hibernate query (i.e. HQL). Below is my query.
query = session.createQuery("FROM StaffDuty where deptId....
1
vote
2
answers
65
views
Why aren't my Django Postgres `ArrayAgg` members sorting?
I'm exploring the use of ArrayAgg and I don't understand why 'histidine-[13C6,15N3]' doesn't occur before 'isoleucine-[13C6,15N1]' in this example:
In [25]: for i in Infusate.objects.annotate(tns=...
1
vote
2
answers
92
views
SQL join 2 table with date, filtered and grouped by a week number
I have 3 tables in SQL:
Agency, booking and checkin (and rooms)
I need to compute a % of checkin / booking, by week number (of begin), by agency
Here somes tables for example
Agency :
id
name
1
first
...
0
votes
2
answers
126
views
SQL error: operand type clash: decimal is incompatible with date
I have the following stored procedure:
CREATE PROCEDURE [dbo].[SearchPaymentsByComp]
@CompId INT,
@OrderByCol NVARCHAR(255),
@OrderByDir NVARCHAR(255),
@SearchDate DATE = NULL,
@...
0
votes
2
answers
125
views
Sort rows by latest group
I have the below dataset which includes 3 columns:
Inspection Id
Inspection Date
Fault Number
Note: I have added in the 2 additional columns 'Comment' and 'Required Sort Order' to help explain what ...
0
votes
0
answers
51
views
Wordpress admin custom post list page orderby meta_value_num doesn't work
Been trying to order the custom post type listing page based on a custom meta field.
the meta field value would be in the form of string and number (pattern: '[string][unsigned]')(examples: 'A1','A2',....
2
votes
2
answers
124
views
SELECT ... ORDER BY <boolean condition>
Having this situation:
SELECT DISTINCT "FieldName"
FROM "TableName"
ORDER BY "FieldName" ASC;
I'd like to have the lines containing '%|%' first followed by the ones ...
1
vote
2
answers
123
views
Postgres inner join where and order by
Is there a way to efficiently order by a text field in a join query (i.e., fast on large datasets)? I understand that I probably need to filter the dataset somehow, to reduce the size of the dataset ...
1
vote
2
answers
91
views
How to correct the syntax for ORDER BY that works but the CASE logic is backwards?
I have the following folders table:
+----+--------+------+
| id | folder | user |
+----+--------+------+
| 1 | Inbox | 0 |
+----+--------+------+
| 2 | Drafts | 0 |
+----+--------+------+
| 3 ...
0
votes
1
answer
89
views
Does MySQL return results ordered by id when using LIMIT with an increasing id condition? [duplicate]
I’m optimizing a query for better performance, and I use the following SQL statement:
SELECT * FROM my_table
WHERE status_flag = 0
AND event_date = '2025-03-25 23:59:59.999'
AND id > 42006893
...
0
votes
1
answer
57
views
Oracle: Ensuring SELECT FOR UPDATE Locks Rows in a Specific Order Before Selection
I have a query in Oracle where I need to:
Order the entire table by a specific column.
Select and lock a certain number of rows using SELECT FOR UPDATE.
However, the issue is that Oracle first selects ...
1
vote
0
answers
67
views
AWS Redshift unload not respecting order by
I defined a redshift table (some fields omitted from this sample) with this DDL:
CREATE TABLE public.my_sorting_test (
timestamp_utc timestamp without time zone ENCODE raw,
filtered boolean ...
1
vote
1
answer
130
views
More than one OrderBy clause in EF Core per Paramter Func<T,obj> and how to build the query more generic
I have a base razor component, that loads data from a SQL database. To pass a sort order to this component, there are two "sort" Func<T,object> parameters and two bool to set asc/desc.
...
0
votes
2
answers
121
views
Order by subset of related field?
I have a model Release. Each release has a type, and depending on that type different types of Credit are considered primary credits. I want to be able to order releases by the Entity names of their ...
2
votes
6
answers
118
views
SQL ASC and DESC ordering on same column based on another column
I want to arrange pending orders by eta in asc order and completed orders in desc order, with all completed orders appearing at the bottom of the list. Not sure if this is possible in a single query.
...
-2
votes
1
answer
101
views
Order by ASC doesn't return any item but order by DESC does
Any known explanation of this? Why Order By ASC doesn't return any item but order by DESC doesn't?
I am using postgres with pg_vector extension
SELECT
langchain_pg_embedding.document,
...
-2
votes
3
answers
83
views
<sqlite> - Order by a specific pattern?
I would like to get my entries ordered by a specific pattern.
For example I have an array like this
arr = [2,5,3,9,4]
Now I want to get the entries from my db by ID in the order of the array. I would ...
0
votes
0
answers
62
views
HQL ORDER BY query with adding days to date column
I use spring boot, and I want to add specific days to date column in mysql database on hql query order by clause. But which results error when I tried. I need to get results in the order of adding ...
-2
votes
1
answer
54
views
Yii2 Active Record Order By Primary Key ID not working [closed]
I have a pretty basic Yii2 ActiveRecord query.
$paperList = Paper::find()->orderBy(['id' => SORT_DESC])->all();
id is my primary key column which is of type int and AUTO_INCREMENT.
When ...
-1
votes
2
answers
54
views
Does order by in a window function add more frames?
Using :
sum(Age) over(partition by Country) as Total
Id FirstName LastName Age Country Total
----------- --------------- ---------- ----------- --------------- -...
0
votes
1
answer
118
views
SQL Group By and Order by with sum
I have this query:
--10/24/24 - UNIT PRICE AND QTY SHIPPED
SELECT
DBO.SHIPPER.PACKLIST_ID, dbo.shipper.SHIPPED_DATE,
DBO.SHIPPER.CUST_ORDER_ID, dbo.SHIPPER_LINE.SHIPPED_QTY,
dbo....
1
vote
0
answers
55
views
How do I group results of a query in wordpress
I've got a custom post type for staff. The fields are first_name, last_name, job_title, telephone, email, and notes. All staff are categorized by location using WP core Category. I need to output the ...
0
votes
2
answers
68
views
Does using ORDER BY on an indexed column in a query cause issues if new rows are inserted during query execution
I have a table Users with id, this table has a million records or more. So when fetching data from the table I am using batching with offset & limit to reduce load on my server.
My question is if ...
0
votes
1
answer
210
views
Having difficulty sorting Snowflake data that contains numeric and non-numeric data
I have a query in Snowflake where I am returning both numeric and varchar values and am struggling with getting the sort to work correctly.
For context, this column is calculated by dividing two ...
1
vote
3
answers
136
views
SQL query left join with sum,group by and order by in MS Access
I'm trying to execute a SQL query with a left join with sum, group by and order by clauses in MS Access.
But the result is not correct - perhaps the SQL code I am using is wrong.
Table Expense
ID ...
0
votes
3
answers
144
views
How to sort all numbers before letters with linguistic sorting?
In an Oracle SQL query which uses binary sorting rules, numbers are sorted before letters. But if the query uses a language specific collation to enable linguistic sorting, then numbers are sorted ...
1
vote
3
answers
119
views
How to sort numbers before letters with linguistic sorting?
In an Oracle SQL query which uses binary sorting rules, numbers are sorted before letters. But if the query uses a language specific collation to enable linguistic sorting, then numbers are sorted ...
0
votes
1
answer
55
views
Can I order by a conditional combination of fields in MySQL?
Example Fiddle
CREATE TABLE Demo (JobID INT(11), Status VARCHAR(250), InvoiceStatus VARCHAR(250));
INSERT INTO Demo (JobID, Status, InvoiceStatus) VALUES (1, "Active", NULL), (2,...
0
votes
1
answer
80
views
How select query from record count more than 1 and count more than 2 with custom column (Option) in MS Access
I'm trying to select query from record count more than 1 (ID&DATE&INOUT) and count more than 2 (ID&DATE) with custom column (Option) in MS Access
so with "NO" in the option ...
1
vote
1
answer
99
views
Why are Oracle and SQL Server producing different sort orders?
I've got a table with a column of BANK_ID alphanumeric (VARCHAR2 in Oracle, VARCHAR in SQL Server) length 12. There are three records with BANK_ID of BARCLAYS, BARCLAYS_LDN and BARC_FRA_EUR.
In Oracle,...
1
vote
2
answers
171
views
How select query from record count more than 2 with custom column (Option) in MS Access
I'm trying to select query from row count more than 2 based on ID and DATE and OPTION in MS Access.
so with "NO" in the option column then the record more than 2 is not included in my sql ...
1
vote
1
answer
83
views
How select query from record count more than 2 in MS Access
I'm trying to select query from row count more than 2 based on ID and DATE in MS Access.
Please Guide me
I want to keep it as a single query.
Thanks
Table Absen
ID
DATE
TIME
INOUT
5008
28-Apr-24
08:00
...
0
votes
2
answers
68
views
SAS proc sql: select for each value the right interval
Suppose there is a list of clients and each client has different contracts that have a due date. For each client, I want to select the contract with the first following duedate after a given reference ...
0
votes
1
answer
89
views
Why Isn't SQLAlchemy's order_by Sorting URLs?
I'm working on a Flask application using SQLAlchemy where I need to consistently sort URLs stored in a database. The goal is to have a consistent ordering of competitor URLs so that when comparing ...
0
votes
4
answers
75
views
Order By Integer column, but based on custom priority
Given:
-- INIT database
CREATE TABLE Result (
ErrorCode INT
);
INSERT INTO Result(ErrorCode) VALUES (500);
INSERT INTO Result(ErrorCode) VALUES (-8000);
INSERT INTO Result(ErrorCode) VALUES (-7777);...
-1
votes
1
answer
55
views
PostgreSQL Custom Order By in Java CriteriaBuilder
Id
Child_one_id
Child_two_id
Parent_id
1
2
3
null
2
null
null
1
3
2
null
1
4
null
null
null
5
6
7
null
6
null
null
5
7
6
null
5
8
null
null
null
9
null
null
null
10
11
12
null
11
null
null
10
12
null
...
0
votes
3
answers
58
views
Different sort order result on two different clients
I get different sorting results when trying the same select on two different clients.
This is a simple example:
select 'CPSC' from dual
union
select 'C1' from dual
order by 1 asc
I get 'CPSC' first, ...
1
vote
1
answer
74
views
C# linq Include OrderBy
I need some help sorting data by Included data. In the example below, I am returning a purchase order where I want to sort the purchase order line items by the line item id.
return await context....
1
vote
2
answers
41
views
Oracle SQL Grouping same value records in particular order
I have simple table of Time and Task columns where it is ordered by Time and has associated task to it as per below example.
Question: How to group the tasks and get the earliest time of every time ...
0
votes
1
answer
148
views
C# sorted get different result from ORDER BY in SQL Server
I need to replicate the exact order produced by another program that used the ORDER BY clause in its SQL query:
SELECT Name
FROM TABLE_NAME
ORDER BY Name
Result:
To reproduce the order on my side, ...
1
vote
1
answer
262
views
How to order by SUM() DESC when using WITH ROLLUP?
I want to use SELECT WITH ROLLUP in MariaDB to get a summary row in the result set, but also order the remaining rows by SUM() DESC. How to best achieve this?
Using the example from the linked ...
1
vote
0
answers
57
views
JPA CriteriaQuery: using same expression in select and orderBy
I tried to write belowed SQL with CriteriaAPI in Hibernate 6.2.6:
select foo.id,
foo.bar,
bar.name
from foo
left join bar on bar.code = foo.bar
order by bar.name;
This is my kotlin code:...
1
vote
0
answers
67
views
How to OrderBy entity results using Map value included in the @Entity as @CollectionTable
I am trying to orderby value of a Map that is included in my @Entity as @CollectionTable @ElementCollection. I try to do this using criteriabuilder and eclipselink.
I provide below the entity example
@...
0
votes
1
answer
47
views
Use of GROUP BY with ORDER BY in MYSQL
My written query is:-
Query 1:
SELECT CONCAT( "There are a total of " ," ", COUNT(OCCUPATION) ," ", LOWER(OCCUPATION) , "s." ) AS ENT
FROM OCCUPATIONS
GROUP BY ...
0
votes
0
answers
49
views
Why the ORDER BY clause works like this? [duplicate]
I need help to find out why this behaviour (not a solution). It's about the ORDER BY clause in SQL Server. It has nothing to do with the related post, because my case it's not about case sensitive/...