Most voted "sql" questions
Structured Query Language (SQL) is a language to query databases. Questions should include examples of table code and structure. This tag refers to the default language, not to be used for questions about the implementation of specific DBMS (such as Mysql, Postgresql, Oracle, MS SQL Server). In this case use the specific DBMS tag. Answers to questions marked with ANSI SQL should use SQL as much as possible.
Learn more…6,771 questions
Sort by count of
-
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
answer6216
viewsJoin columns in one SQL column
I have three columns, belonging to the same table in the database, these being: Growth, Financial Autonomy and Rationliquidity; All columns are bit type. What I need is to group the three fields in…
-
2
votes2
answers1662
viewsInsert multiple values into a table
How do I insert several values into a table, but into a single one query of sql?
sqlasked 6 years, 8 months ago André Tavares 21 -
2
votes2
answers5112
viewsWhat is a Dataset and what is its function?
Creating my first database applications (SQL Server), I connect by passing my string and using the Sqlcommand class to pass the query. But searching other sites, I see that access to the bank is…
-
2
votes2
answers9612
viewsSelect that takes the last 30 days from the current date
Good morning guys, this is a part of query which I used to search the last days from the current date. It works as expected when I put -20, but by putting -30, nay. WHERE viacao_os.creation_date…
-
2
votes1
answer14068
viewsConversion from VARCHAR to INT
I’m trying to do INNER JOIN but the fields are in VARCHAR. In a field I have cod_authorization = 749831164 And in the other field I have num_aut = 000749831164 Because of the zeroes "Left"…
-
2
votes1
answer746
viewssplit 1 column into 2 in sql server giving update
I use SQL Server 2012 I have the following problem, in a table there are records of municipalities and two respective Fus but there is the need to divide this column into 2 one of municipality and…
-
2
votes1
answer554
viewsQuery returning duplicate values
people I posted here on topic SQL query with duplicate items I just have another question... have a sql: SELECT TABNOV.CODIGO_ANDAMENTO, TABNOV.NUMERO_PROCESSO, TABNOV.INSTANCIA,…
-
2
votes1
answer51
viewsHow to select and play values in the same column
Example: select 'a' as 'letras', 'b' as 'letras' I want to play the letter 'a' and the letter 'b' in the column 'letters', but with this code it returns 2 columns with the same name, but I want to…
-
2
votes1
answer213
viewsPerformance with Exists
A colleague mentioned that by making a EXISTS in SQL, it is recommended to use DISTINCT 1 to improve performance. For example, instead of doing: SELECT * FROM CLIENTES WHERE NOT EXISTS (SELECT…
-
2
votes2
answers1455
viewsDatabase/slow server
I’m starting in the database area and I notice a great slowness in some banks I use in virtual servers. In my case I access a windows that has a postgres and with an average frequency my scripts are…
-
2
votes2
answers213
viewsInsert multiple lines into Informix
I use a Informix bank and I have to do 3500 Inserts. Informix runs line by line and this is impractical. How do I insert all lines at once? Example: insert into tabela (coluna1, coluna2, coluna3)…
-
2
votes3
answers536
viewsHow to show quantity of sales per month payment in SQL Server
I’m getting the following result: Mes | QtdPorMes 1 | 124 2 | 102 3 | 84 4 | 32 I’d need it to stay that way: Mes | Boleto | Cartão | Total 1 | 100 | 24 | 124 2 | 82 | 20 | 82 3 | 34 | 50 | 84 4 |…
-
2
votes2
answers49
viewsHow do I list all fields from one table plus a random value from another table?
I’m having a problem making the relationship with two tables, tb_adm_anuncios and tb_adm_anuncio_banner. For each ad I have 4 banners, and to list these ads I need: **Anúncio:** -Nome do Anúncio…
-
2
votes3
answers2216
viewsSQL - Bring only 1 year records back
I’m trying to realize a SELECT that brings me only customers who haven’t bought for 1 year without duplicating the customer. Down with the code I’m trying to: SELECT DISTINCT p.ID, p.Nome_Fantasia,…
-
2
votes2
answers860
viewsHow to create a report in Sql Server with information by date
I am created a system for output management, one of my tables stores the output history information, it has the following columns, IDpedido, DataDoPedido CodProduto, QuantidadeProduto CustoProduto…
-
2
votes1
answer14523
viewsError The multi-part Identifier "..." could not be bound
I am trying to make the following select and it returns me the error The multi-part Identifier "..." could not be bound in Importacontratoaux.Contratoid select AreaReclamacao.Descricao from…
-
2
votes4
answers2013
viewsFind the best-selling item along with a particular item
To explain, I prefer an example: I want to find out which item is the most sold along with the salty chicken. For this, I tried the following approach and failed miserably by lack of technical…
-
2
votes1
answer359
viewsnode extraction via postgresql
It is possible via commands in Postgres to process vector data. I have a table with data that represent the displacement of objects and need to extract final and initial Vertice. This is possible…
-
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
votes1
answer96
viewsQuery - Comparison of Distinct Bases with equal columns
How would a query that selects between two tables according to the value of a specific column ? For example: I have two tables that contain account number and Balance, I need to know which accounts…
-
2
votes1
answer741
viewsHow to capture mysql (Duplicate entry) error and display a message on the screen to the user using codeigniter?
How to capture mysql error (Duplicate entry) and display a message on the screen to the user using codeigniter? Error Number: 1062 Duplicate entry '123456' for key 'process' INSERT INTO processo…
-
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
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
answers876
viewsQuery SQL to select student and student name
I have this simple relational model, and I need a query that selects the student and the student’s name.…
-
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
votes2
answers80
viewsDoubt select in two tables
I’m making a system in PHP, but I’m stuck because I can’t find the solution to a challenge. I have 2 tables, a call objetos and another call gavetas. I have several names of drawers registered in…
-
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
answer1113
viewsHow to Insert into the table if the record does not exist
How to insert in the table if there is no record, as for example there is the table turma_materia, has the following information: +----+-------+---------+ | ID | turma | materia |…
-
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
answer627
viewsOPENROWSET - How to assign a variable instead of the file name to open?
I do this command and I do it right: SELECT * FROM OPENROWSET( 'Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;Database=\\00.000.00.0000\Arquivos\TI\Arquivos\252203408.xlsx;HDR=YES', 'SELECT * FROM…
-
2
votes3
answers261
viewsHow to send selected data to an ftp server
I am developing a project in c# and right now I have to select a line from a Datagridview that I created, create a text file with that data and send the created file to an ftp server. I’ve done some…
-
2
votes4
answers97
viewsCreate a SELECT to bring the difference of two tables
Has the table bisemanas which stores 26 fixed bi-weeks and the table outdoor_bisemanas which stores the reserves of billboards according to the bi-week chosen. Edit: What I want is a select which…
-
2
votes1
answer905
viewsERROR #1111 - Invalid use of group Function (SUM | COUNT)
This query gives me the total attendance of two parliamentary groups (e.g: PS, PSD) between two dates: SELECT DISTINCT a.partido, (SELECT COUNT(presencas.assiduidade) FROM presencas, reunioes WHERE…
-
2
votes1
answer52
viewsDifficulty mounting an SQL statement
I’ve been cracking my head here to mount an SQL, maybe someone can help me. I’m trying to draft a report to charge the relationship notes that were eventually deleted. The user registers an nf in…
-
2
votes3
answers2371
viewsDownload all columns of all tables containing a text
I would like to find out which are all columns of tables in a database in a way that it is possible to search a word in these columns. Let’s say I have a database I don’t know the structure of but I…
-
2
votes1
answer69
viewsChange date to business date (Mysql)
I need to change the date of my database, considering the Business Date used in the company I work. Here, a commercial month is between 26/M-1/AAAA and 25/M/AAAA. Where M-1: last month. For example,…
-
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
answers2740
viewsSelect the first and last day of the previous month
I have the following query: select ADDDATE(LAST_DAY(SUBDATE(CURDATE(), INTERVAL 1 MONTH)), 1) primeiro_dia, last_day(sysdate()) ultimo_dia That returns me the first and last day of the current month…
-
2
votes1
answer103
viewsHow to make a Unique field for each Foreign key?
I am studying mysql and came across the following situation and would like to know if there is a solution structuring my tables to solve this. Assuming I have two tables; user (id, user, password)…
-
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
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
votes1
answer195
viewsHow to make a "for each" on Sqlite
I have an A table with n records. For each record of this table, I want to get information from a field x to make a select and, based on the results of select, make a insert in a table B. Only I…
-
2
votes3
answers590
viewsHow to remove apostrophes from a variable
I have a text Edit PRODUCT that comes like this: 'STICKER 478', with apostrophes. How do I make it come out like this: STICKER 478 on sql server? I’ve tried that and it doesn’t work: DECLARE…
-
2
votes2
answers82
viewsSearch in two tables
I have a media table with the fields id_midia, nome, tipo and another table of synonyms that has the fields id_midia, sinônimo. I need to make a query where it checks the two tables if the term…
-
2
votes1
answer1371
viewsdecimals of a variable Numeric field depending on CASE in SQL
I have a query where, depending on a parameter, I need the result in a field to be 5 decimal places or 2 decimal places, this is possible in SQLSERVER 2008? Example DECLARE @VALOR DECIMAL(18,2),…
-
2
votes2
answers587
viewsSort by the result of the sum of two SUM - MYSQL
I need to order a query by the result of the sum of two sums. ORDER BY SUM(SUM() + SUM()) I tried the following: SELECT SUM(campo1 + campo2) AS soma1 , SUM(campo3 + campo4) AS soma2 , SUM(soma1 +…
-
2
votes1
answer214
viewsCount and group by day range
SELECT loc.loc_pac as registro, datediff(dd, pac.pac_nasc, getdate()) as 'dias' from loc with (nolock), pac with (nolock), str with (nolock) where loc.loc_pac <> '' and (loc.loc_pac =…
-
2
votes4
answers19922
viewsLimit the number of SQL query lines
I have the following Query SELECT estado, num_ocorrencia FROM bra_ocorrencias WHERE nome like 'João' ORDER BY num_ocorrencia DESC It returns me all the states with the most relevant occurrences…
-
2
votes1
answer31
viewsSettings Many to Many code fast Migration
good afternoon! I have this many configuration for many in my project. public class Usuario { public Usuario() { this.LocalTrabalho = new HashSet<LocalAtendimento>(); } public virtual…