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
-
4
votes1
answer698
views -
4
votes2
answers2348
viewsHow to make a user in SQL Server 2008 view only a VIEW?
I made a View to send to a customer, but I can’t pass the login and password to the general access. This way I created a user (cliente_view) and I would like this to view only the created View…
-
4
votes3
answers2377
viewsStructure table day and times (schedule type)
I need to create a table that contains days and hours of operation of an establishment, a kind of agenda. This table should represent every day of the week and on each day contain the opening and…
-
4
votes1
answer339
viewsUse IN or multiple OR? Which one performs better?
I have the following queries in Mysql: 1º: Using multiple devices OR SELECT SUM(qtd) FROM produtos WHERE qtd > 10 and (status = '0' or status = '4' or status = '7') 2º: Using IN SELECT SUM(qtd)…
-
4
votes4
answers11110
viewsHow to group SQL results by month and year?
I would like to know how I can query the Mysql database and group the records by year and month. At the moment I first make a query to get the year records, then for each year I use a for() to…
-
4
votes1
answer176
viewsmysql driver is not found when the application is rotated from a jar
I have developed an employee registration system. In this system the data persistence is done in a mysql database. When running the program by the package the system works normally, but when…
-
4
votes2
answers1634
viewsSelect records smaller than the current date and time
What is the best way to query the database where the data is smaller than the current date and time SELECT * FROM agenda WHERE agendamento < '".date('Y-m-d H:m:s')."'…
-
4
votes2
answers4792
viewsCheck if it already exists in the table before entering record
I need to include a record in a table, however before inclusion to avoid duplicity it is necessary to do a check. As I have a column ID with as property AUTO INCREMENT, I can’t use the INSERT IGNORE…
-
4
votes2
answers498
viewsCheck values with 0 included in Count() even if they do not have values
I need to consult the number of banknotes issued with template 55 to create a report. The problem is that I’m needing to put zeroed values in the quantity column even though it has no value at all.…
-
4
votes0
answers285
viewsService returns me cast error when consumed
I decided to make another post, since the subject is another, although in the original post, in the comments we touched on the subject, but no depth. I have that mistake:…
-
4
votes2
answers75
viewsReturn a case sensitive record
I own a constraint in the bank that is all with your name capitalized. As I do a count to find the same one using the UPPER? 'Cause I want to pass the where a tiny name to return. This one of mine…
-
4
votes1
answer356
viewsDatabase Locked Sqlite/Java error
I have the following problem: in an Insert that I am trying to accomplish, I don’t know if it is an error in the database or something in the java programming, but every time I try to perform an…
-
4
votes2
answers422
viewsCalculating average time
In my bank I have a table that has the fields entrada, saida, the two fields have the format D-MM-YYYY H:M:S, would like to make an average calculation. Ex: The average waiting time is 30 min Based…
-
4
votes1
answer46
viewsQUERY - Can anyone help me mount this query?
I have these 3 tables below: "users", "Friends" and "posts". I want to take all my friends who are in the table of Friends and display their posts, taking the name of each and their image (which are…
-
4
votes1
answer247
viewsImport txt file into Postgresql 9.6
Guys, I have the following problem: I have a file in txt format with the following information: 1;Helder;Masculino;GO 2;João;Masculino;RJ 3;Maria;Feminino;PR 4;Pedro;Masculino;MA I used this example…
-
4
votes3
answers1000
viewsSelect with the last record
I need to value the inventory of the company I work for and for that I will take the last value of the items. I was using the MAX, but I realized that if I did this, it would return me the highest…
-
4
votes2
answers1906
viewsCalculate Difference between 2 dates (has time in them)
Hello, I would like to make the following calculation. Starting Date = 11 September 2017 at 11:35 am Final Date = 11 September 2017 at 12:35 pm It should appear to me 1:10 am. Another example:…
-
4
votes2
answers1474
viewsIs it possible to do an INSERT and UPDATE in the same query in java?
I wonder if it is possible to make one INSERT and a UPDATE in the same query, that is, in the same operation. I’m using the following to do both operations. public Connection conn = null; ... conn =…
-
4
votes2
answers1965
viewsget mysql data using javascript and ajax
I’m developing a web app (case interest, follow link) and it was going all right until I got to the bottom: The field NCM is a tag input with a disabled attribute. The information within it comes…
-
4
votes2
answers502
viewsAdd previous line in mysql
I have a launch line, in which this line would need to receive the value of the previous line +1, some example of how to do this? Table structure: CREATE TABLE `lancamento` ( `data` VARCHAR(10) NOT…
-
4
votes1
answer129
viewsHow to make a SELECT between two tables and their WHERE’s?
I take the category ID, and with it I search the subcategories. For this I am using WHERE’s. How would you look using INNER JOIN? The WHERE’s thing got me confused <?php namespace…
-
4
votes2
answers558
viewsSort by the number of repetitions in a column?
In a query in Mysql I need to select the results and sort the results based on the amount they repeat using the column id_livro, for example: My table comments: +----------------+-------------+ |…
-
4
votes2
answers7919
viewsHow to join 2 select in mysql
I have 2 select which are basically identical, changing only 1 table. I’m trying to put the 2 together in a single select, but I’m not getting it. Follows the select: SELECT DISTINCT a.id,…
-
4
votes1
answer103
viewsDatabase maintenance c#
I have a system in another language and I need to create an update for this system, but it needs to be run Mysql Scripts for database maintenance. I searched in Java and found Maven that has all…
-
4
votes5
answers3132
viewsWhat is the difference between comparison operators on Oracle?
In Oracle there are several operators to make "different" comparisons, such as: <> ¬= != ^= Example: Select * from tabel where nomeTabela <> 's'; Select * from tabel where nomeTabela !=…
-
4
votes1
answer462
viewsWhat is the foreign key (SQL) for
For what I’ve been researching, when pulling the information of two tables in a database, JOIN is used, which has nothing to do with foreign key. So what’s the point of declaring a field as Foreign…
-
4
votes1
answer144
viewsWhy does Oracle not have autoincrement?
Assuming that it is known that Oracle has the resources of the table quence. I would like to understand why they only recently implemented the autoincrement in Oracle, since it was a feature…
-
4
votes2
answers2352
viewsReset datetime time with SQL
Today, man SELECT returns the following date: 2017-11-16 10:37:16.000 I’d like you to return 2017-11-16 00:00:00.000, can help me with this formatting?…
-
4
votes3
answers158
viewsDoubt about sql query
I have a question. I believe it is nothing complex, but I could not solve. For example, I have this query: select * from Paciente where ClinicaID = 3 Your result would be these 3 records:…
-
4
votes2
answers683
viewsHow to run INSERT only if the record does not exist?
I’d like to wear something like sqlite insert into table (column) values ('')if not exist;…
-
4
votes2
answers7073
viewsPut If to Where
I got the following Where WHERE 1 = 1 AND (0 = 0 OR 1 = 1) inicio do if AND (2 = 2 OR 3 = 3) fim do if How would I do if? The idea is that a value per parameter comes and if that value satisfies the…
-
4
votes3
answers2090
viewsHow to add Count output from different tables in SQL Server?
How to add up the result of Count of different tables in SQL Server? Example: Table WORKS has 755614 Records SELECT count(*) from OBRAS; Table TITLES has 85106 Records SELECT count(*) from TITULOS;…
-
4
votes1
answer836
viewsSQL Server Composite Key
I have the following situation: I have a table ItensVendas where I need to apply a composite key to the fields VendedorId and ProdutoId, however I have some duplicated data, ie I can not apply the…
-
4
votes2
answers227
viewsRemove "OR" condition from LINQ query
I have the following method: bool naoUsarNomeCliente = String.IsNullOrWhiteSpace(filtro.NomeCliente); long codigoExterno; bool naoUsarCodigoExterno = !long.TryParse(filtro.CodigoExterno, out…
-
4
votes1
answer3994
viewsReset Auto-increment SQL Server
Good morning, I created a new table in Sqlserver and I am testing some scripts to popular the table and I came across the following situation, in my tests I am doing the Insert in the table checking…
-
4
votes5
answers1602
viewsChange return /Date(1386295200000)/ to date format
I have a return from json that comes so from SqlServer: /Date(1386295200000)/ How to convert to date format dd/mm/yyyy?
-
4
votes2
answers948
viewsHow to get random results in SQL with different Dbms?
Based on this existing question on Soen and wanting to bring interesting and useful content to Sopt I ask this question: How to get random results in SQL with different Dbms? I’m leaving an answer…
-
4
votes1
answer194
viewsWhere Mysql search by full word
I have a database and would like to know how I do to search for the data by typing the full result using Where Example: ID NOME CODIGOS 1 | Joao | 9714,51,100 2 | Maria | 50,9714,88100 Ai wanted to…
-
4
votes3
answers124
viewsSelecting Active Batch
I’m studying about appointments at Sqlserver and have the following scenario: I have a lot table that has the following fields: Table of Lot (Lot) Id INT ProdutoID INT Preco SMALLMONEY Inicio…
-
4
votes3
answers759
viewsThe null value automatically becomes 0
I’m doing a vehicle registration, I need it to register put that whenever a vehicle is registered the value zero instead of putting the value null, I tried by default, but it does not record the…
-
4
votes1
answer107
viewsHow to search data from a third table based on the associative table
To put it in context: I have a table called principal and another called school. There are schools that directors who are registered with the name of the school. In this case, these schools are…
-
4
votes1
answer111
viewsBring only one product per affiliate to sql server
Good day I need to bring only one product per affiliate, but in my table I have several times the same product just changing the date, I would like to take the product of the last date. What do I…
-
4
votes1
answer1312
viewsSee The Employee Salary Amount on a Given Date
Does anyone know what a query would look like to see what a certain employee’s salary is at a certain date? The table of the salary adjustment history of each employee has the following fields:…
-
4
votes3
answers259
viewsFilter a select, without duplicate SQL queries being returned
The problem is to return a SELECT with only those schedules that are no longer accepted by the user. I’m trying to use the schedule table that has already been accepted, which has both the user ID…
-
4
votes1
answer48
viewsquery executes in the database but in the project points error
I have a query native: SELECT dist.nome Distrito, enti.nome Entidade, dist.id_distrito, dist.codigo_dne, dist.id_entidade, dist.id_municipio, dist.id_uf, dist.flag_ativo, muni.nome Municipio,…
-
4
votes1
answer236
viewsDifference between select a. or b
What’s the difference of doing the search by select a. or b.? Example: select --a.num_duplicata,a.data_prorrogacao,a.seq_duplicatas, a.cli_dup_cgc_cli9 as cgc9,a.cli_dup_cgc_cli4 as…
-
4
votes1
answer3377
viewsWhy is the use of ';' mandatory in the WITH clause?
I’ve always used the WITH in my consultations, however, I never understood exactly why is required the ';' before the clause WITH. The Error is very succinct, but it gives an idea that the WITH…
-
4
votes3
answers3810
viewsWhat is the difference between a View and a Stored Procedure in SQL?
I have come across SQL Views and also stored procedures. I would like to understand better, what is the difference between a view and a stored Procedure and what are its purposes? It would be…
-
4
votes3
answers89
viewsOFFSET next to COUNT(*) returns nothing?
When I make a query this way are returned me the data correctly(At the moment 2 lines): SELECT * FROM noticias ORDER BY data_noticia DESC LIMIT 30 OFFSET 2 But I need to know the number of lines…
-
4
votes3
answers596
viewsQuestions about the Count sql command
When I write the command select count(carga > 40) from cursos; what counting logic the command count is running? This command worked on mysql however it returned me a result that I could not…
sqlasked 6 years, 2 months ago Isabela Medeiros 41