Most voted "order-by" questions
66 questions
Sort by count of
-
10
votes1
answer5341
viewsOrder By with List<>
It is possible to make a OrderBy in a List<> setting the value for comparison? Example: mRel.OrderBy(s => s.Status == EnumModel.StatusGeral.Novo).ToList() My Code:…
-
8
votes1
answer528
viewsORDER BY only day without hour
In Mysql I have a column timestamp calling for dia_cadastro (2016-06-21 11:27:32), in consultation I want to give a ORDER BY only on the day, and disregard the time. That is, if they have products…
-
7
votes1
answer729
viewsError using Group by in a Mysql VIEW
I created a VIEW to return in a single query the main data I need. CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW v_historicoProcesso AS SELECT p.protocolo AS…
-
7
votes1
answer776
viewsMysql very slow sorting for results with many records
I have two tables, the first is used to group the data of the second with some information about the set, in order to facilitate the pagination of the contents. Table 1: - id INT(11) NOT NULL…
-
6
votes1
answer876
viewsCombination of 4 numbers in Mysql
SGBD: Mysql Problem: List all possible combinations between the numbers "1,2,3,4", so that they do not recur between them. Example: 1 2 3 4 12 13 14 21 23 24 31 32 34 41 42 43...…
-
6
votes2
answers1150
viewsSort month that is in full in Postgres
I need to make a ORDER BY in a table mes which has the months in full and in Portuguese (Janeiro, Fevereiro...). It has no relation to any other column in the table. It is possible to do this?…
-
6
votes1
answer1251
viewsHow to filter separate dates by day , month and year in Mysql
Hello, I have a table "Meetings" in Mysql with the following structure: id:Int(11), subject:String(40), day:String(2), mes:String(2), year:String(4), active:String(2) except in the field day the day…
-
5
votes1
answer822
viewsQuery slows down with ORDER BY
I have a problem, I have a query and when I use the ORDER BY she gets too slow. Note: I created an Index for the premium field and another for the score Follow the full query: SELECT p.id AS…
-
5
votes2
answers86
viewsHow does ORDER BY draw columns in case of a repeated value?
Suppose I make one SELECT sort of like this: SELECT * FROM "users" ORDER BY "createdAt"; In this context, if I have data that has the same value in the field createdAt, how SQL will sort these…
-
4
votes1
answer235
viewsGrab the latest message from a conversation (GROUP BY)
I have the following query: SELECT cp_mensagem.mensagem, cp_mensagem.dh_envio, cp_projeto.id as id_projeto, cp_projeto.nome as nome_projeto, cp_pessoa.id as id_freelancer, cp_pessoa.nome as…
-
4
votes1
answer657
viewsRandomized and ascending order query in MYSQL
I have a table where I have the student’s name and his score, I need to pick up 5 random students and display them in ascending order of the score. I tried to do it this way, but he’s just randomly…
-
4
votes3
answers3103
viewsHow to perform UPDATE with ORDER BY on sql server?
I would like to perform an update ordering the results of the same, for this I wanted to run an update like this: UPDATE pessoa SET nome = 'Jose' WHERE sobrenome LIKE '%Betalla%' ORDER BY nome But…
-
3
votes1
answer10006
viewsSort the latest registrations according to the registration date
Sort the latest ads registered in mysql, with the dates closest to the current date using PHP Field type (date) in mysql is (date) This is my query: SELECT * FROM frame_anuncio WHERE ativo = 'Sim'…
-
3
votes1
answer1429
views -
3
votes1
answer3954
viewsINNER JOIN WITH ORDER BY
In MYSQL I have two tables, product and product_photo. In the product table_photo has a field that calls first that normally its value is 0. In the administrative system of the site there can be the…
-
3
votes1
answer438
viewsHow to sort by two parameters with Laravel 5.4?
I am making a decreasing order to list winners, but it is based by note. My search is as follows: public function getHistorico($id_avaliacao) { return $this->where('avaliacao_id', $id_avaliacao)…
-
3
votes2
answers646
viewsSort Dropdown with jquery after append
In case the user does not find the desired item in the list of dropdown, it can include a new item, for this I used the function promptof javascript, and then the user enters the name and click on…
-
3
votes1
answer142
viewsList last logged in users (GROUP BY AND ORDER BY)
I have two tables (user and log), and would like to list users ordering by last logged in. I am using the GROUP BY to join the logs (since a user may own more than one). The problem occurs when I…
-
2
votes5
answers1449
viewsSorting in query - Leave last registration in first and then sort by a field
I’m having to create a query that returns the data ordered by a specific field, for example name, but the first return line should be the last id. You can do this with sql? Let’s assume I have the…
-
2
votes1
answer36
views"order by clauses" can create conflicts between themselves?
It is possible that if we have several clauses in the order by, these conflict with each other? For example: select candidato.nome from candidato, perfil_oferta, prova_de_afericao where candidato.bi…
-
2
votes0
answers56
viewsSort by deep JSON column
I have a column called data, which has, for example, this JSON [{"name": "unit", "value": "2", "validator": ["required"]}, {"name": "name", "value": "teste", "validator": ["required"]}] I need to…
-
2
votes1
answer1039
viewsSort list by a string property with number
I have an object of the type Ata where I own the property NroAta which corresponds to the number of the minutes in question, but in grid when I sort by this number, it ends up putting the numbers in…
-
2
votes2
answers229
viewsDynamic SQL result sorting
First good afternoon, I work specifically with Java in the Back-end using Webservices Rest and Postgresql, after some professional enhancements I was instructed to pass ordering and pagination of my…
-
2
votes3
answers628
viewsCreate a custom SQL order
I have a table (groups) in SQL with the following structure: id | name | description | display_order | ... The field display_order was defined as UNIQUE and must be an integer. Its main function is…
-
1
votes1
answer782
viewsOrder by SQL Server under Procedure
Hello, I have the following situation: I need to select the amount of care of people of some age groups and of those who are male and female. I have the following tables: cadastro (id, natendimento,…
-
1
votes2
answers223
viewsSELECT sort by the quantity of another SELECT
I have two tables in MYSQL: account: id apelido_usuario 1 caio 2 manoel 3 josé product idconta status 1 3 1 3 1 1 2 3 3 2 I made a SELECT like this: SELECT * FROM conta WHERE apelido_usuario…
-
1
votes1
answer321
viewsFrom CTE in SQL to relational algebra
How to pass a CTE in SQL for relational algebra, for example: with publicacao_cte (nome,nr_publicacoes) AS ( select candidato.nome, Count(1) as nr_publicacoes from candidato, cv, ficha_inscricao,…
-
1
votes1
answer92
viewsLinq to SQL - Dynamic sort by column index
I’m using a component called datatables.js (https://www.datatables.net/) to display my tables and it owns the property Serverside, that I call, in Ajax, my list from somewhere. It sends the…
-
1
votes1
answer46
viewsSQL query using order by filtering by log
I have the table: | cod | hora | produto | Amostra | Min | Max | |-----|-------|---------|---------|-----|-----| | 1 | 08:00 | 96722 | 1 | 100 | 200 | | 2 | 08:23 | 96721 | 1 | 90 | 90 | | 3 | 08:50…
-
1
votes1
answer482
viewsHow to order a group in the mysql query?
I’m trying to order a query in the database grouping the information, but this showing the first registered in the database, but I want the last. SELECT * FROM base_rating AS B JOIN historico_rating…
-
1
votes2
answers62
viewsMYSQL: sort by specific Rows within SELECT
I’ve been trying to figure this out for three days and I haven’t found the answer anywhere I have a table in the database where I need to do a SELECT on all products but they need to be sorted…
-
1
votes2
answers165
viewsGROUP BY WITH ORDER BY
How to make a GROUP BY in the MySQL respecting the results obtained with the ORDER BY Ex: ID(Primary Key) | nome | codigo | tipo 1 | Item E | 5 | 1 2 | Item D | 4 | 1 3 | Item B | 2 | 1 4 | Item C |…
-
1
votes0
answers14
viewsORDER BY between two datetime columns
I have two datetime columns: data1 and data2. I need to sort by the shortest date between the two columns. If data2 is not zero, displays data2 line; If data2 is zero, displays data1 line; How do I…
-
1
votes3
answers789
viewsProblem sorting sql with orderby Date in postgresql
I have the following query that results in the union of the total sum of an account and the installments select sum(total) as total, datavencimento from ( select sum (con_valoraserpago) as total,…
-
1
votes1
answer30
viewsSelect in Mysql sorted by the WHERE condition
I have a database in Mysql designed like this: id, nome At the following values: 1, Banana 2, Maçã 3, Uva 4, Laranja I have a select like this: select * FROM table WHERE id = 2 OR id = 1 OR id = 4;…
-
1
votes1
answer578
viewsORDER BY or LIMIT. What is processed first in SQL Select?
Friends, what is first processed in SQL Select? "Order by" or "Limit"? For example, if I have a table with cities of several states. Then I search the cities with more than 100 thousand inhabitants…
-
1
votes1
answer81
viewsSearch with group by
Suppose the following table records authors' posts on a blog. An author may have several posts. So I have several repetitions of authors in this table of the different posts that he did. How I…
-
1
votes1
answer225
viewsselect distinct in temporal table sql server
I have the following code: (is from a table that the representatives have the same code, which generates duplicated values, I solve this by taking the most current representative, in short the last…
-
1
votes0
answers56
viewsSort mysql query correctly
I have a query to fetch some values, however the value does not return me correctly. In the example below you will notice that user 1 is below user 2. In this case the order should be in this…
-
0
votes1
answer133
viewsIt’s a bug in Cakephp - Sort Aliases?
I’m trying to sort a query by relevance with cakephp using Paginator, but simply it ignores the alias, I already searched the manual but so far I haven’t found the solution, the query works…
-
0
votes1
answer311
viewsSort the Table by the value closest to the parameter passed in stored procedures
how to sort a table according to the approximate value of a parameter passed in a stored previous Ex: let’s say that in a table the name field has the following values: Tiago, Iago and Thiago and I…
-
0
votes0
answers213
viewsSort datatable by date of records
I have a code, which when starting, it creates a table using datatable. The data from this table comes from my Mysql database. I do not know for sure how is the ordering of my records, if I am not…
-
0
votes0
answers109
viewsDoctrine2 + pdo_sqlsrv createQueryBuilder Order By with varchar field does not work
I’m creating a method that takes values for createQueryBuilder() from parameters. I tested in my local database with pdo_mysql driver and it worked perfectly, sorting both by a field of type int…
-
0
votes1
answer1026
viewsSelect with max(date), penultimate(date)
I have a chart with product code and date of sale. I would like to make a select by taking the product code, the date of the last sale and the date of the penultimate sale with group by code. It is…
-
0
votes4
answers5283
viewsSort a SELECT in Mysql by a letter
How can I make a SELECT query in Mysql that sorts the results and initially displays those that start with a specific letter? Ex with the letter P: Paul Patricia (1st ones starting with the letter)…
-
0
votes1
answer291
viewsHow to query MYSQL in 2 columns and sort 1st results of title column and then Description column
I’m setting up a job agency website and I have a search that searches the field title and description, what the person searched, as per the query below: SELECT * FROM vagas WHERE (titulo LIKE…
-
0
votes1
answer412
viewsmysql select order by starting with today’s date
I have this appointment that seeks birthdays of the month: $mesHoje = date("m"); $sqlAni = $pdo->prepare('SELECT * FROM aniversario WHERE MONTH(dia) = :mesHoje ORDER BY dia ASC');…
-
0
votes1
answer297
viewsUsing Angular "track by $index" with paging, filtering and sorting
good morning! I’m having a huge problem trying to use the Smart Table, with paging, filter and searching in my table. I had the table working when I converted a JSON that consumed by an object…
-
0
votes2
answers84
views -
0
votes1
answer668
viewsMysql - Sort before grouping
I need to make a selection that brings the last users who logged in, without repeating the names. The problem is that the command below first groups and then sorts: SELECT usuario FROM tab_logins…