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
votes1
answer619
viewsUsing in SQL coalesce with Date
I have the following question. In SQL your doing so works. ...and coalesce(tb_cadastro.cod_produto,'') = coalesce(:COD_PRODUTO, coalesce(tb_cadastro.cod_produto,'')) and ... Where the COD_PRODUTO is…
-
2
votes1
answer279
viewsEXCEPT equivalence | INTERSECT & exists | not exists
Would be the EXCEPT | INTERSECT always equivalent to a not exists | exists? Having the following consultation SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM…
-
2
votes2
answers700
viewsQuery with Left Join without returning duplicate value
I have the table tableA and tableB. I’m making a select of all fields of both tables joining the same by left Join select * from tableA left join tableB on tableA.id = tableB.id But the relationship…
-
2
votes2
answers224
viewsCondition for INSERT INTO
I need SQL to check that in the '@variable' sent there is a value equal to 1, 2 or 3; If true enter the value 1, otherwise enter the value 0. Note: the table and column can be given as examples as…
-
2
votes2
answers1061
viewsWhat are real and practical examples in the use of Stored Procedures?
When participating in an interview for the position of developer, I come across a question related to Stored Procedure (SP) and at first I have theoretical knowledge on the subject, but I have never…
-
2
votes0
answers63
viewsUpdate table with XML field and in different databases
I have two banks SQL SERVER 2012 installed on server A and server B, I need to insert and then make a Update in the server table B via linkedServer by the A server, but these tables have fields XML,…
-
2
votes1
answer63
viewsTotal sales per month grouped by seller
I need to bring a list of executives and total sales per month, all regardless of whether they sell in the month or not. For years I am focused on front-end and I have never done anything with sql,…
sqlasked 6 years ago Maicon e Nanda Blumenau 442 -
2
votes1
answer56
viewsPostgresql build error
Would anyone know if there is an error in the query below: select name, cast(Extract(day from payday) as int) as 'day' from loan; I cannot find the reason for a build error in the URI.…
-
2
votes1
answer58
viewsPostgresql build error - Error
I’m trying to run this query in postgresql but it gives compilation error: select can.name as 'name', ( ( (sco.Math 2) + ( sco.specific1 3 ) + ( sco.project_plan * 5 ) /10 ) as "avg" from candidate…
-
2
votes1
answer9584
viewsSyntax error sql, #1064
I’m trying to create a table in my phpmyadmin database. SQL CREATE TABLE IF NOT EXISTS 'chat' ( 'id' int(11) NOT NULL AUTO_INCREMENT, 'time' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 'username'…
-
2
votes1
answer301
viewsFunction Code and (+)
Problem : Resolution: SELECT NOME, DECODE(COUNT(CODIGO_LIVRO),0,'NENHUM',COUNT(CODIGO_LIVRO))"NR LIVROS" FROM AUTORES A,LIVROS L WHERE A.CODIGO_AUTOR=L.CODIGO_AUTOR(+) GROUP BY NOME ORDER BY 1;…
-
2
votes0
answers56
viewsAdd comment to the one column with Entity core framework Fluent api
How do I add a comment to a column. In sql I do so: ALTER TABLE Tabela MODIFY COLUMN 'nome' varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Teste' AFTER `nome`; How to do in…
-
2
votes2
answers351
viewsApply between in an hql in c#
I am trying to apply a between with two fields of a part of my form, are dates and vehicle ids, I do not have much knowledge of how it models this by HQL in nhibernate with c#, I wonder how it would…
-
2
votes1
answer27
viewscompare dates within the sql query
I need to compare the date registered in the bank +10 days with the current date and display the student that the current date is greater than 10 days, but this within the sql query. Is there a…
-
2
votes1
answer197
viewsDifference between connecting tables with WHERE and with INNER JOIN
I was learning SQL and came across the following instructions: SELECT tbl_Livros.Nome_Livro, tbl_Livros.ISBN_Livro, tbl_Autores.Nome_Autor FROM tbl_Livros, tbl_Autores WHERE tbl_Livros.AutorID_Livro…
-
2
votes2
answers485
viewsINSERT INTO with Mysql filter
I am trying to create an INSERT INTO in an X table by making a filter in table Y, but I get a syntax error. I’ve researched what could be wrong, but not found. INSERT INTO products ( SELECT * FROM…
-
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
votes1
answer231
viewsUse ON UPDATE CURRENT_TIMESTAMP when changing specific field
Example scenario Table: usuarios Campos: id, nome, sobrenome, senha, timestamp_alteracao Question The field timestamp_alteração, should only be updated when the field senha is amended. Doubt There…
-
2
votes1
answer3849
viewsHow to delete primary key (PK) in Mysql?
I have the following table in Mysql: The id column is primary key. I would like to remove the primary key from this table. How can I do this? Thank you.…
-
2
votes1
answer420
viewsBest way to generate Holerite, I seek a more viable solution
I developed an application that generates Holerites, and for this I need to process data from 4 tables. Employees -> Companies -> Salaries -> Discounts I want to show my user the following…
-
2
votes1
answer59
viewsConditions different from the same column
I have a table called anuncios: id | nome | finalizar | datafim 1 | teste1 | N | 0000-00-00 2 | teste2 | S | 2018-12-05 I’d like to make a SELECT listing only records where the column value…
-
2
votes3
answers76
viewsHow an array comes from the database in an input
<input type="text" class="form-control" name="lanches" id="lanches" value="<?php echo $resultado['lanches']; ?>" > I have that above input where it receives that array that is inside the…
-
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
answer379
viewsConvert SQL to LINQ
I have the following table CREATE TABLE `ultimaposicaorastreadores` ( `Id` CHAR(36) COLLATE utf8_bin NOT NULL DEFAULT '', `Serial` BIGINT(20) NOT NULL, `DataGps` DATETIME NOT NULL, PRIMARY KEY USING…
c# sql entity-framework entity-framework-6 linq-to-entitiesasked 6 years, 10 months ago b3r3ch1t 805 -
2
votes2
answers528
viewsHow to use the SUM aggregation function in a NHIBERNATE query?
My consultation consists in knowing the NumCarroId, TotalGasto and VlrUnit, in Sql I managed to do that but when I play in HQL returns the following error: Application of GROUP BY next to the SUM to…
-
2
votes3
answers140
viewsGROUP BY last registration per month and year how to do?
I’m making an appointment at the bank, follow my table below id | valor | mes | ano | 1 39.69 3 2017 1 7.69 3 2018 3 9.69 4 2015 3 3.69 2 2016 2 5.89 3 2017 2 39.69 8 2018 need to bring the result…
-
2
votes3
answers264
viewsSelect Group by Month
SELECT dataVen, Sum(valorTotal) as valorTotal FROM cad_cr2 Group by MONTH(dataVen) The above query returns the following values: I wish it were so, grouped by month: I have done many researches and…
-
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
votes1
answer425
viewsSelect last records in ascending order
I know there are many topics with this subject, but none of them have been able to help me so far. I need to select the last 8 records so that they are organized in ascending order. Example of the…
-
2
votes0
answers39
viewsData do not send to the database
So, I created a CRUD class, the code is not returning any errors, but it is not being inserted in the database. I have tried to arrange several ways, but I can’t find any way. CRUD.class.php class…
-
2
votes1
answer2089
viewsALTER TABLE changing column name
When using ALTER TABLE to modify the column name in a table, we need to define the data type again: ALTER TABLE tabela CHANGE COLUMN nome_antigo novo_nome tipo_dados; If the data type is not…
-
2
votes1
answer66
views2 Groupby in a Mysql query
In Mysql I have a login table with the field day and User ID: 28-01-2019 - a 28-01-2019 - a 29-01-2019 - a 29-01-2019 - b 29-01-2019 - b 30-01-2019 - a 30-01-2019 - b 30-01-2019 - c What I need is…
-
2
votes0
answers207
viewsRelationship between three tables - Postgresql
need to make a relationship between three tables in the database in Java, created the two entities and the methods of the two entities, now need to insert a relationship table that has only two…
-
2
votes1
answer371
viewsSelect columns with no specific name
I am developing a C# application that consumes data from a spreadsheet and at some point I need a query string that will feed a variable. For example: strComando1 = "SELECT TOP 2 ColunaGenerica1,…
-
2
votes1
answer472
viewsStore SQL data in a Javascript array
I have a question regarding receiving SQL data in a Javascript array. I have the login information and everything, related to the server, but the issue is not the connection, is to save the data in…
-
2
votes2
answers1707
viewsTable structure in user questions and answers template
I have a doubt in the structure of some tables and I hope you can clarify in detail below. Setting The system will generate a way to create forms and questions dynamics, in order to be answered by…
-
2
votes3
answers93
viewsHow I take this amount
Good evening, I need a help with the code below. This code already works for what I need. Geolocation to display the nearest users, but how I get the distance value??? $user = $con->query("SELECT…
-
2
votes3
answers37
viewsSelect entries between two dates
Good, I have a view " Gp_vw_cons_faults " that contains the initial and final date of when a client is missing. I want to collect all the records of a particular client in a given period of time. I…
-
2
votes1
answer190
viewsHow to check if a Sqlite3 Database is valid?
I was testing and seeing what happens if android create a database with wrong input values. For example, if I unintentionally typed NOOT instead of NOT or INTEGET instead of INTEGER, I expected SQL…
-
2
votes3
answers202
viewsSql query bring repeated result
How do I list only the sector column that has repeated data? in case, just show the sector 150 SELECT setor,count(quantidade) as quantidade, usuario FROM arquivo_coletor GROUP BY setor,usuario ORDER…
-
2
votes2
answers80
viewsHello guys. Can anyone tell me why the result of the consultation below is bringing in the first 4 records the Zeroed Balance?
Can anyone tell me why the result of the consultation below is bringing in the first 4 records the Zeroed Balance? I’m calculating the entrances and the exits. Calculate correctly if there are…
-
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
votes1
answer308
viewsSQL - Transform different values of a Column into multiple columns with Count in each of them
My question is how to separate different values of a column into several columns and give a Count in each item according to the name in postgres, follows example below How are you: --TIPO…
-
2
votes1
answer854
viewsSelect from time to time
I’m trying to ride a sql to check if there is any record between times informed but not leaving, I did some tests but unsuccessfully. For example, a bank record containing these two times, as…
-
2
votes3
answers86
viewsProblems with SELECT RIGHT JOIN
I have two tables, A and B. Na Table A, I have a column with names of machines (Cutter, Baler, Packer and Rewinder) and in the other column some causes that made them stop (As Lack of Electrical…
-
2
votes1
answer59
viewsDoubt about SQL Injection/mysqli_real_escape_string
I’m having doubts about SQL Injection in PHP. I have a class that has the user object, and there has name, age, etc. Then I put in the variable query something like: insert into…
-
2
votes4
answers27603
viewsSQL - Calculate percentage in the same select
Based on the query below, I need to add the column Percentage, being the calculation of Passed on top of the Total but I do not know how to take the values of this same select to insert in the…
-
2
votes1
answer251
viewsSub select with COUNT and SUM
I have the following query: SELECT s1.suprimento, e1.numeroserie, s1.capacidade, e1.numeronotafiscal, e1.valorunitario, e1.datanotafiscal FROM public.estoque e1, public.suprimento s1,…
-
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
votes3
answers180
viewsMysql - Create an alias by concatenating multiple fields
Is it possible to create an alias by concatenating other fields? Ex: SELECT u.nome, u.sobrenome AS nome_completo FROM usuarios u In the example, I want to concatenate u name. and u surname. and…