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
-
0
votes1
answer84
viewsRelationship model and entity
Guys, I’m setting up a website that has the artist chart and an artist can play more than one musical genre, as I would put in the database the genres that the artist plays ?
-
0
votes2
answers1349
viewsQuery to list number of occurrences
I am trying to list how many CATEGORIES each PERSON has but I only want to return if PERSON has more than one CATEGORY. My query is like this and does not return anything. And I know there are cases…
-
0
votes1
answer135
viewsSQL - Import data from a file
Hello, friends as they are? Good I am facing a problem to import a previously created table: The following return message when I try to import into Mysql: Static analysis: 3 errors Were found During…
-
0
votes0
answers269
viewsSQL query for ASP.NET page with C#
On my client’s website, I have an SQL query that brings the result of the level of readiness of several collaborators. Only that, for now, I can only transfer to the page the result of the query in…
-
0
votes3
answers1584
viewsMerge the result of a query on the same line from the sequential
I have the following appointment: SELECT * FROM SERQUENCIAL WHERE DATA BETWEEN '2017-01-01' AND '2017-01-19' She returns: +--------------+-------+------------+-----------------------+ | ID_PESS NOME…
-
0
votes1
answer855
viewsFor each result, a new line in php
I have a database where in the table users I have the columns: +----------+------------+----------+------------+----------+------------+ | imp_cod1 | imp_local1 | imp_cod2 | imp_local2 | imp_cod3 |…
-
0
votes4
answers898
viewsSQL Count Parole
I have the following table +----------+----------+ | data | valor | +----------+----------+ | 16/05/15 | 1 | | 16/05/15 | 0 | | 16/05/15 | 1 | | 16/05/15 | 0 | | 17/05/15 | 2 | | 17/05/15 | 1 | |…
sqlasked 7 years, 10 months ago spiderman123 111 -
0
votes1
answer112
viewsReturn result from a select inside a loop
I’ve been trying for a few hours to get the result of a select that is within a pgsql function. I don’t have much experience with sql. I researched a little but I was not very successful. Follow my…
-
0
votes1
answer233
viewsSQL - Select with possible concatenation
I created a query that concatenates my results. It is a table with names and to which range (square) they are classified. The table is called consulta_readiness and the fields are name and squared:…
-
0
votes1
answer270
viewsProblem connecting to Firebird database
Guys, I’m with a project to do a report that does a search on a Firebird database and I have the file . FB ready to create the bank. However, in connection with dbschema it presents me this driver…
-
0
votes3
answers1329
viewsSelect data with Between in Varchar format
I am redoing the question because I could not get the desired result, I would like to select in the field date but the between is not working, I believe it is due to my date field being in VARCHAR…
-
0
votes1
answer70
viewsHow to return values from different columns without repeating?
I’m trying to capture and print on the screen all the categories of a table, but I wouldn’t want them to repeat themselves. Note that there are 4 columns of different categories below:…
-
0
votes1
answer35
viewsFill bank by expanding a given value on so many items
I have in the bank the registration of the building, with the number of rooms qtdSala, among others. I am trying to insert, in another grid, each room according to the value entered in the qtdSala,…
-
0
votes1
answer438
viewsSelect related to another select, pulling data from the database
I need to create a form that pulls the options from the sql database. So far so good, I did a while inside a query in php; echo '<SELECT NAME = "setor">'; while ( $temp =…
-
0
votes2
answers215
viewsSelection with various differences conditions (SQLSERVER)
I wonder if there is any way to improve this selection: SELECT * FROM table WHERE id <> 15 AND id <> 17 AND id <> 23 ... id <> N I don’t have a certain set interval and the…
-
0
votes1
answer113
viewsleft Outer Join in a clause or
I have a problem with a query, that I need to do a left Outer Join from one table to another, or considering the values as 0, if any, basically what I was doing was the following. select B.coluna…
-
0
votes1
answer168
viewsQuery 2 tables in a sql database and display repeated values
I have 2 tables in my database, a call pessoas and another call resultado, I am filling the table result with the draws made by mega sena, the table result has the fields: data, dez1, dez2, dez3,…
-
0
votes1
answer124
viewsupdate of lines followed according to items selected in listview
we have a table 1, which has building and rooms, building A, sala01, room 02.... , we need to put people in these rooms. These people come from another table(2), which fills the listview. This Lvi…
-
0
votes2
answers151
viewsHow to map an Excel column to a Database column
I needed help to do the specific mapping of a column of an excel file to a column of a database. I can read the excel file but I just can’t map the file to the column I want in the database. If you…
-
0
votes1
answer3159
viewsQuery sql with longer and shorter date limit
My code should return values from the database, related to the current day (today), but only related to the month and day, I searched a lot but could not find something to help me $data_atual =…
-
0
votes1
answer284
viewsTransform Brute Inner Join to Laravel Join
I’m updating a system that is developed in pure PHP and I’m putting it in Laravel, however, I’ve never made more than a Join and with "AND" parameters so I would like you to help me, how can I put…
-
0
votes2
answers98
viewsRepeat condition in WHERE at the time of query
Currently use WHERE coluna IN (1,2,3,4) in my consultation. Only I realized that the IN works as a kind of "OR", it generates me a small problem, because the ID are features of a product. These…
-
0
votes1
answer373
viewsI need to display a TOTAL field in a PIVOT query
I have the query below that returns the total quantity in stock of the products for each city. Each city is a column and products are displayed in rows. Now I need to display in a field (column) the…
-
0
votes1
answer41
viewsSqlserver in repositories
I have to send an application project through a Github repository, I managed to make the application work perfectly front-End, Back-End and LOCAL database, my doubt is: Can I export Sqlserver to a…
-
0
votes3
answers171
viewsDoubt - Update SQL Server 2012
When the update below is run for the first time, the field comes out correctly in the way I want it to be below, but if I run it again, it comes out that way. What I want is that regardless of how…
-
0
votes1
answer63
viewsDelete Constraint after taking its name
I’m spinning the next query to obtain the name of 2 constraints: select TC.Constraint_Name from information_schema.table_constraints TC inner join information_schema.constraint_column_usage CC on…
-
0
votes2
answers98
viewsSum of fields for input
Good morning, I got the following: <div class="form-group col-md-2"> <label for="campo4">Valor da Peça</label> <input type="text" class="form-control"…
-
0
votes1
answer60
viewsDate no postgresql.PL/SQL
with the function below I want to make this function compare the current date with the date stored in the bank.HOWEVER ,THERE IS NO RETURN . create table mercado( id integer, diaEntrega date, valor…
-
0
votes1
answer166
viewsSQL UPDATE SUM VALUE NOT NULL
dataTmp referencia nStock 2017-02-18 DC01234567 NULL 2017-02-18 DC01234567 NULL 2017-02-18 DC01234567 NULL 2017-02-19 DC01234567 0 2017-02-19 DC01234567 0 2017-02-19 DC01234567 0 2017-02-20…
-
0
votes2
answers95
views -
0
votes2
answers543
viewsPick up data using Join in two table 1 for many
good morning, I need to perform a select of two tables that are related 1 to many: Table 1: products Table 2: price group I need to get all prices from the price group table, which may have 1 or…
-
0
votes1
answer33
viewsSelection Using FROM TABLE
I have a table and a function that returns a pipeline, only the function needs to receive a data from the first table, I imagined that the selection would be something like this: Select…
-
0
votes1
answer122
viewsProcedure Price Range
I’m trying to create a design that according to the price range takes a different field from the table. Create Procedure BuscaPreco @preco decimal, @faixa1 int, @faixa2 int, @faixa3 int,…
-
0
votes0
answers242
viewsInsert sql with WHERE NOT EXISTS rule does not work
In this Sert below only works until the first rule of "Where" then no longer works Example WHERE descricao ='$ccusto' // funciona perfeitamente. Mas se uso o where abaixo WHERE descricao ='$ccusto'…
-
0
votes1
answer1846
viewsHow to use the Contains method in a search using the Entityframework
I’m trying to make the following consultation sql, using the Entityframework: select * from pedidos where pedidoID not in (select pedidoID from agendamentos); I conducted some research and…
-
0
votes1
answer1002
viewsImport decimal with comma
On SQL Server, I’m trying to run a SELECT in a *.csv file as follows: SELECT * FROM OPENROWSET(BULK 'C:\Minha_Pasta\meu_arquivo.csv', FORMATFILE = 'C:\Minha_Pasta\format.xml') AS Contents…
-
0
votes1
answer207
viewsExpire Mysql user time
I’m making a system of login in C# where the login user will be verified his login, password and the time left to use the system. Until the login and password check part I managed to do, but I’m…
-
0
votes3
answers596
viewsHow to optimize SQL to filter results
The filter may occur in the following scenarios: Without any input filled 1 (a) input filled Combinations of inputs, including all SQL to be optimized: $cnpj = isset($_GET['cnpj']) ? $_GET['cnpj'] :…
-
0
votes1
answer535
viewsAjax, Javascript and PHP form
How can I make a form with a UF field and a selection field with label Cities that will be filled through AJAX and that when selecting the UF the JS function connects to the server and returns the…
-
0
votes1
answer1088
viewsConnection between two DBMS Sql Server
Is there any way beyond Linked to connect two DBMS ? Problem: I need to use the tables of another bank that is on another server with the SQL SERVER installed. My current server is also SQL Server;…
-
0
votes2
answers63
viewsPut records on one line only
Problem: The user makes several logins and various logouts, wanted to put the login and logout on the same line next to the user name, with the login date and the logout date, on the same line. All…
-
0
votes1
answer630
viewsPermission to change only one table column in Postgresql
good night! I’m using Postgresql and in it I have a table called Products. When the user visits a product through the site I give an UPDATE in this table to increase the column visits. The problem…
-
0
votes1
answer591
viewsConvert SSIS data from varchar to int
I’m locked into a conversion by SSIS, scenario: I have a CSV file, which I need to import into a table already created in the database, In this table of the database I have a column already…
-
0
votes0
answers73
viewsDatabase connection error
When trying to make a connection to the dodo bank I have the following error: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@delphix-db-1.homolog.infra:1521:BRMQA10 at…
-
0
votes1
answer129
viewsOrganize Period column in SQL in ascending or descending form
Staff I have the following question/problem I’m doing a select on some accounts and organized by the name of the file, but I need to organize for the period but I’m not able to because it is not a…
-
0
votes1
answer92
viewsConcatenate Lines with the same User
I have the following consultation: SELECT e.id_taxe, u.nm_user, dt_taxe, SUM(e.vl_taxe) as vl_taxe FROM taxe as e INNER JOIN user as u ON u.id_user = e.id_user WHERE id_enterprise = 86 AND (dt_taxe…
-
0
votes2
answers236
viewsError in codeigniter querry Builder
I have a problem in the SQL of my query, follows: $sql = "SELECT cl.codigo, pa.codigo AS codigo_participante, pa.nome AS nome_participante, cl.usuario, cr.data AS data_geracao, cl.validade, cl.chave…
-
0
votes1
answer247
views12 month columns => 1 value column + 1 month column
I have a table with SQL connection (PERVASIVE) with a column for each month, that is, 12. In order to better work the data, I need to transform the 12 columns in only 2... a 1st with the values that…
sqlasked 7 years, 8 months ago deathseeker 11 -
0
votes2
answers838
viewsSelect picking up previous line
What I have to use in SQL SERVER 2008 to get the line before a certain enclosure. For example if in my Where below if the alert is = to 99 want to know the alert and the speed before the alert.…
-
0
votes0
answers86
viewsDelete duplicated postgresql lines
My code automatically inserts data into a database, making the BD too large and sometimes with repeated information. For this, I want to use the Slowly Changing Dimension (SCD) method so that: - A…