7,701 questions
-1
votes
1
answer
54
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
65
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
38
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
39
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
47
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
111
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
42
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
50
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
0
answers
18
views
ORA-01791: not a SELECTed expression on Order [duplicate]
When I put order by, I get an error that ORA-01791: not a SELECTed expression, and I've no idea what happen, could you please tell me what should I do?
Select distinct
FL.MEANING||' : '||FL.Tag||' : '|...
0
votes
1
answer
49
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
116
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
90
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
74
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 ...
1
vote
1
answer
44
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
67
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
70
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
156
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
70
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:...
0
votes
2
answers
45
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
57
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
67
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
50
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
...
0
votes
3
answers
40
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
66
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
34
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
105
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
121
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 ...
0
votes
0
answers
20
views
How reading from pre-sorted plan node can return less rows than from index scan in top-n query in postgresql?
I was optimizing a query and encountered this strange query execution behaviour.
Query:
select active_preleads.id
from active_preleads
left outer join personal_scores
on active_preleads.id = ...
0
votes
0
answers
24
views
Count button clicks on custom post type cards and order them by button clicks in Wordpress
in Wordpress, I have created a custom post type to display as a list of cards. Inside this post type, I have created a custom field that displays button with a link to an outside website. I would like ...
1
vote
0
answers
46
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:...
0
votes
0
answers
54
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
40
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
44
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/...
0
votes
2
answers
45
views
Oracle multiple order by query optimization
My Table structure & data-
CREATE TABLE BRAND_OFFERS
(
ID NUMBER(15,0)
, NAME VARCHAR2(80 CHAR)
, OPEN DATE
, CLOSE DATE
, ENROLLED DATE
);
-- expired offers
insert into ...
1
vote
1
answer
55
views
How can I improve performance of a joined PostgreSQL query that orders by columns from different tables?
My query looks like this
select "vehicles".* from "vehicles"
left join "users" on "vehicles"."user_id" = "users"."id"
where "...
0
votes
2
answers
53
views
Getting ORA-01722: invalid number error, When executing query
In 3 versions of Orale (11g, 12c, 21c) I create the mytable as follows :
create table mytable (id number, log_time date)
and, then I inserted some data into the table,
insert into mytable values (1, ...
0
votes
1
answer
54
views
Is there any way to get nulls last without calling order by?
Let's say we have a query as follows:
SELECT a, b, c FROM my_table ORDER BY a nulls last
Is there a way to define a query to
SELECT a, b, c FROM my_table
with a column nulls last, without ...
0
votes
2
answers
163
views
Prisma ORM how to order by GREATEST()
I have a database table with two columns updated_at and children_updated_at and I would like to show the latest modified records first based on the SQL function GREATEST(updated_at, ...
0
votes
1
answer
35
views
Unable to find solution for a certain sorting scenario
I have a scenario where I regularly need to maintain records in a table that defines workflow order definitions to add and remove stages which puts the IDs in a non-deal order (cant change the IDs ...
0
votes
1
answer
56
views
Ordering users by "rank counts" column with or without ORDER BY in MySQL
I have a game and it have 10 worlds and each world have 20 levels.
and have a ranks table like this:
id
user_id
world_num
level_num
rank
#
userId1
1
1
3
#
userId1
1
2
1
#
userId1
5
15
12
#
...
0
votes
0
answers
39
views
SQL, return user position based on specific ORDER BY using MySQL 5.7 [duplicate]
I have tables
users: (id, name)
scores: (id, user_id, value, created_at)
How can I calculate rank of user by sum of value, but if sum for some users the same upper should be user with highies last ...
0
votes
5
answers
107
views
Unknown column [col_name] in 'order clause'
Select CONCAT ( Name, '(' , LEFT(occupation,1) , ')' )
FROM occupations
UNION
Select
CONCAT ('There are a total of ', Count(Occupation) ,' ', occupation, 's' ) as line
FROM occupations
Group by ...
0
votes
1
answer
55
views
How does CASE in SELECT affects ORDER BY result
Consider the following schema:
create table cities (
id serial primary key,
name text not null
);
insert into cities
(name)
values
('NY'),
...
0
votes
1
answer
63
views
Enhance ordering on 280M rows of a column
I've an application which shows records of a SQL Server table inside a grid after applying pagination. User can filter or apply order onto any column.
Problem arise when that table becomes too big ...
-2
votes
1
answer
85
views
Can I put a couple of std::functions with unspecified return type into a container in C++?If so, how to do that?
I want to write a generic sorter in C++. I have some code like this.
template<typename T>
class sorter {
public:
template<typename R>
bool RegisterDimValueFetcher(const std::...
1
vote
1
answer
56
views
Order by author name when a book may have more than one author
I've got a book catalogue db. Each book can have one or more authors. Example:
book #1 by John Red
book #2 by Fred Green and Steve Blue
book #3 by Ben Brown
ARTICLES table:
id
title
1
Book1
2
Book2
...
0
votes
1
answer
46
views
What is the correct syntax with orderby for this OData expression used for Azure.Data.Tables in C#?
I searched likely everywhere, but don't find a right page of where somebody can explain me how write the right syntax for orderby.
I think there are problems with this ampersand, it's a query-operator ...
0
votes
1
answer
102
views
Order by extreme performance impact
I have a complex query in SQL Server which take 70 seconds to complete with 3,000,000 records.
When I remove the two ORDER BY clauses, it just takes 0.5 seconds to complete.
SELECT TOP 100
...
0
votes
1
answer
41
views
MySQL: Ordering
I have a table with the names and birth dates of kids in a class. I want to create a query which sorts the kids first by whether they were born before 2010 or after and then sorts them by name.
The ...
0
votes
2
answers
44
views
Wordpress and MariaDB: Sorting (internally using inner join) doesn't work?
I use WAMP on my dev machine running MariaDB. On the server I use MySQL. The main page is a list of events sorted by a metavalue: event_date. Here's the query as generated by Wordpress
SELECT ...