Most voted "query" questions
Query or *query* refers to the act of recovering data previously stored in a computerised system from certain parameters and/or filters, by means of a specific command or operator.
Learn more…1,160 questions
Sort by count of
-
2
votes1
answer90
views(SQL) Add "Count 0" when no record
Hello, I’m picking up for a query in the database where I need to pick up how many subscribers have registered in a tournament, the problem is that I need to also bring the tournaments that do not…
-
2
votes0
answers283
viewsGet Street and number in a string in an irregular expression
I have a table that I have all the address in one column, but it is irregular. Below are some of the occurrences: BR 459 KM 153 RODOVIA ITAJUBA MF KM 05 Rodovia MG353 2Km 55 RUA 37 QUADRA 4 LOJA 611…
-
2
votes1
answer30
viewsQuery to catch a student’s mistakes and successes
I would like a query to catch mistakes and hits from a particular student of the following table below:…
-
2
votes1
answer109
viewsMultiquery PHP PDO - SQL Server 2012 - IIS 8.5
Is there a problem with running multiple queries with the same PHP PDO code? Example: <?php // Retorna $con include 'conexao.php'; // Suponhamos que dbo.minha_tabela tenha apenas três campos,…
-
2
votes1
answer178
viewsQuery not working, problem to compare years
Hello I’m trying to elaborate a query to perform an Insert, as it uses only database data I am a select for this. My problem is in Where clause in which either end of operation has to be null or end…
-
2
votes1
answer79
viewsQuerys have stopped working
I recently made a change to the table and after that SELECT and INSERT INTO stopped working. At first the INSERT INTO could not include data in the last column that includes (centid), returned…
-
2
votes4
answers4389
viewsSelect from previous months
I need to do select data from previous months, month by month. My query is like this: SELECT * FROM VIEW_INCD WHERE MONTH(DH_CRIA_INCD) = DATEPART(mm,GETDATE()) - 1 AND YEAR(DH_CRIA_INCD) =…
-
2
votes1
answer504
viewsI need to select sequences of numbers in a field of a table column
I have a 'Text' column in my 'process' table. Text consists of a VARCHAR (220), in this text I need to identify a specific word pattern. In this case a sequence of numbers with a "-" to separate:…
-
2
votes1
answer66
viewsSelect random ID between 2 and 4
It is possible to randomly select the ID by placing, for example, the ID numbers that can be drawn (2/4)? Note: Only one line of this selection should be returned. I put this code but it wasn’t:…
-
2
votes0
answers158
viewsHow to return a MAP using JPA’s native Query?
I need to consult a bank that is already established, populated and maintained by another application. So I don’t have the entities in my project and I didn’t want to create. I am using Spring Boot…
-
2
votes1
answer118
viewsHow to use order by stop ordering month names in Oracle
Hello, I would like to know how to solve this problem. I would like to take the name of the days of the month and sort them and not the numbers of the corresponding months. Follow the query I…
-
2
votes1
answer36
viewsmysql subquerie
Guys I’m with the following structure: CREATE TABLE Cliente ( Id_cliente int NOT NULL, Nome_cliente CHAR(30) NOT NULL, Endereco CHAR(40), Telefone char(12), PRIMARY KEY (Id_cliente) ) Engine=InnoDB;…
-
2
votes1
answer235
viewsPick up day of the week in a select
I need to know how to get inside a select (with LEFT JOIN, INNER JOIN) take the day of the week from a field of a table, compare and see which day of the week, if it is 1 add 2, if it is 7 add 1?…
-
2
votes3
answers2459
viewsDoubt SQL Working Days Query
Good night! Guys, I need to know a following result. I want to bring the working days grouped by month and year from April to June of this year 2017. Example: Ano Mês Dias Uteis 2017 Abril 19 2017…
-
2
votes1
answer260
viewsSQL Server Binary File
how do I download images, content, files that are stored directly in the database in binary form? I ask this, because I am in a data migration and the layout (spreadsheet in excel) of the new system…
-
2
votes1
answer64
viewsQuery SQL summing fields from one table with criteria from another
I would like to do a query that adds for example the name of the equals by date (here I will put the period, for example 01/03 to 22/03), the problem that I have two tables, one of individuals where…
-
2
votes0
answers33
viewsi wanted to make a query that returns me the following data in mongodb
COLECTION GAMES { id : 10, casa : "Sport", visitante : "Chapecoense", horario : "2017-07-20 11:00:00" } GAMBLER COLLECTION { nome : "wedson", apostas : [ { idjogo : 10, opcao : 1, valores : 1 } ] }…
-
2
votes1
answer62
viewsString search in database using Linq C# wpf
I have a bank and I want to run a search in the name field, but I also want the customer to be able to search for parts of the string or even with uppercase and minuscule letters. by the time my…
-
2
votes2
answers102
viewsRelationship dates as a result of SQL query on Oracle
Good afternoon, When carrying out the following consultation SELECT CD_ATENDIMENTO,DT_ATENDIMENTO FROM ATENDIME I get the following return However, I need to return only the results that have less…
-
2
votes1
answer3680
viewsSQL to count records that have a field with repeated value
Staff I need a Query that does a value count I have in the bank On my system, I have a multiselect that can select more than one option. I wanted a help from you, I never touched with query, I need…
-
2
votes1
answer19
viewsConverting columns into rows by concatenating the results
I have the following select : SELECT pedido, item FROM pedidos How do I get the result of it in columns and step to row concatenating with -? Example: Upshot pedido item 1 batata 1 arroz 1 feijão 1…
-
2
votes3
answers52
viewsMultiple foreign keys in a single query
Well, I’m having some problems creating a query in mysql that searches several tables in a single query, I searched here in the stack, I found some similar questions, but I couldn’t understand the…
-
2
votes2
answers94
viewsAdds WITH query within another query
Guys, how to add the query below as a subconsulta. Consultation with WITH: WITH tabela (projeto, operadora) AS ( SELECT p.projdesc, tt.tartitulo FROM tarefa tt INNER JOIN projetos p ON p.projid =…
-
2
votes3
answers895
viewsReturn Id’s That Are Not in Database - MYSQL
Problem In a table X and I own N records, but these records are not sequential (throughout Insert, Id will always be larger than the previous one, but not necessarily the next number). I need to…
-
2
votes2
answers87
viewsI have this query and I’m not able to group by month
DECLARE @Year INT = 2005, @Month INT = 7 SELECT --SequenceNo = ROW_NUMBER() OVER(ORDER BY OrderDate), Year = Year(convert(int,OrderDate,111)), case Month(convert(int,OrderDate,111)) when 1 then…
-
2
votes3
answers2314
viewsHow to calculate two columns and compare the result with another column?
I have a table, where I am bringing two different results with the query below: select sum(qtde_pontos) from dbo.tbl_cc_ponto where re = '9289' and natureza_operacao = '2' and data_lacto >=…
-
2
votes1
answer2431
viewsSelect with Laravel/Eloquent
I have the following select in my controller: $turmaAlunos = DB::select(' SELECT alunos.ST_ALUNO_ALU, alunos.ID_ALUNO_ALU FROM alunos WHERE alunos.ID_ALUNO_ALU NOT IN ( SELECT…
-
2
votes3
answers640
viewsGrouping by day and by date period
I have a query of the period 26 a 30-06 that brings the following result: Data_Cancelado Cancelados 27-06-2017 4 29-06-2017 5 However, I want it to come this way, ie,. Data_Cancelado Cancelados…
-
2
votes1
answer104
viewsSearch in multiple tables
Hi, I’m trying to search 3 different tables, check my code: $buscando = $pdo->query("SELECT * FROM filmes WHERE nome LIKE '%$busca%' AND status='ativo' ORDER BY nome ASC"); The tables would be:…
-
2
votes2
answers395
viewsHow to extract the date-time of a given XML field in a string - Query SQL Server 2012
Good afternoon! Guys, in my log table there is a field called logdescricao and in this field it stores several expressions. For example: <log expressao="7085"><par traduzir="N">André…
-
2
votes2
answers136
viewsNull Result Coming in query
Good morning, I need a help from you, I have a query in my system is with a problem, it brings 4 results, only 1 of these 4 is coming with null value. I will post my query below SELECT Title,…
-
2
votes1
answer1021
viewsConsultation with MAX(DATE)
I am trying to generate the query below as follows. Cliente Tarefa Data da Ultima Providencia Teste 16555 04-07-2017 However, is generating duplicate, IE, I want to take the last date of the last…
-
2
votes1
answer879
viewsHow to search data from a table using other reference?
I’ll give you a simple example... I have a table 'products' that has in the columns, id, product name, value. I have another table 'users' columns, id, name. And another table 'buysdosusuarios' id,…
-
2
votes2
answers569
viewsSplit a query
I need some help from you guys, i have a query on my system, which has 4 cases SELECT TOP 3 * FROM ( SELECT Title, SUM(Count) AS Count FROM ( SELECT CASE WHEN EstadoId = EstadoIdAutor AND EstadoId =…
-
2
votes1
answer417
viewsPerform calculation in SQL command
I performed a command of select on my table estoque where I bring the supply model, your current amount and what is your minimum amount in stock, for that I made the query as follows: SELECT…
-
2
votes1
answer386
viewsForeach with 2 conditions
I’m trying to put two conditions on the foreach, but I’m not succeeding. The idea is as follows: the client accesses the site in the following URL: /room/balcony and appears only products that have…
-
2
votes2
answers1233
viewsDate Working Hours - SQL Server
Guys, I have a question. In the query below, in the tarexpiration field, he is counting the hours normally, however, I want to count only the working hours. NOTE: Already has a useful hours function…
-
2
votes2
answers428
viewsHow to make a query that brings only the count of an uninterrupted sequence?
I want the counting of uninterrupted values of the current year backwards, until the first occurs NULL. Example: Several people make donations to an NGO annually and this is stored in a database,…
-
2
votes1
answer513
viewsGrouping Data Preferably-MYSQL
I’m trying to group equal lines, but based on a value. I know it’s possible through a sub-query, but how I’m using inner join I couldn’t apply. SELECT * FROM Concessionarias C inner join…
-
2
votes1
answer153
viewsProblem in Query Builder Laravel
I am in doubt in a query with joins in my project, when running Select directly in the database I have no problems, but when building with Query Builder I get no results. Where would I be missing…
-
2
votes2
answers127
viewsDoubt in Mysql query
Query that I am using SELECT os_id,os_data,os_processo,os_solicitante,os_tipo,os_cliente,os_empresa,os_adverso,os_local, os_comarca,os_advogado,os_preposto,os_documentos,os_status,login_nome,…
-
2
votes1
answer82
viewsMerge Names into a line
Good afternoon we use SQL SERVER 2008 as the official database server and we have the following query : SELECT P.NOME AS [PROFESSOR], STIPOCURSO.NOME AS [NÍVEL DE ENSINO], SPL.CODPERLET AS [ANO],…
sql sql-server query sql-server-2008 string-concatenationasked 6 years, 7 months ago Nathann L. J. Lima Alcantara 21 -
2
votes1
answer864
viewsUsing data from one select within another?
Two tables tbl_orcamento and tbl_itens the budget table has a column with the following status. 1 = orcamento aprovado 2 = ordem de compra emitida 3 = ordem de compra aprovada To tbl_itens has some…
-
2
votes0
answers83
viewsSqlite recursive query
I’m starting with sqlite and would like help with a recursive query. I have 3 tables (generic example): CREATE TABLE IF NOT EXISTS tab_componente ( id_comp TEXT NOT NULL PRIMARY KEY, desc_comp TEXT…
-
2
votes1
answer153
viewsCount/Dense_rank sql grouped
I’m trying to group the lines by group on sqlserver and as a result I want to: CICLO | CODFIL | CODITPROD | ROW 1 | 1 | 10 | 1 11 | 1 | 10 | 2 12 | 1 | 10 | 3 1 | 2 | 10 | 1 11 | 2 | 10 | 2 1 | 3 |…
-
2
votes4
answers209
views -
2
votes2
answers406
viewsSelect dates that are not in the table
I need to compile a report for a client with the billing for each day of a given month. Until then beauty, the problem is that now he wants even the days that have no sale, are shown in the table…
-
2
votes1
answer630
viewsNodejs query in SQL Server
Hello, guys I need to make a query filtered for days in SQL in a Nodejs application, but during the POST that’s when I filter the Nodejs accuses me of a value conversion error. When running get I…
-
2
votes1
answer79
viewsSum subquerys values separately
I have a problem in this query below: select sum(tb1.l1) * 0.3, sum(tb2.l2) * 0.3 from ( select setor, total_geral as l1 from mobile.auditoria where month(data) = month(now()) and year(data) =…
-
2
votes1
answer1210
viewsSelect with subquery to catch previous record
I have a user readout log structure by reference. As shown below. SELECT L.LeituraID, L.UsuarioID, L.Referencia, L.Leitura FROM Leituras AS L |-----------|-----------|------------|---------| |…
sql database sql-server query performanceasked 5 years, 12 months ago Danilo Ribeiro da Silveira 143