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
answer570
viewsHow to format a number in percentage within Javascript?
Gentlemen, I am developing a billing monitoring panel. I want to turn this number 56% directly into my Javascript code. Follow an excerpt of my code, it is directly fed by a query of my SQL. This is…
-
0
votes1
answer60
viewsSending emails that belong to a group
I need a help, I am developing a mailing system that allows sending to a set of email belonging to a group, I managed to do a part now, my txt_para field should receive the name of any group and…
-
0
votes2
answers155
viewsRemove 1 day from a specific date
Good morning, everyone! I would like a help regarding the database, where I pick a date and after I pick up this date I need to remove 1 day from it, thus pulling the result from 1 day prior to the…
-
0
votes0
answers46
viewsSELECT in a time period in a datetime column
I have the following column id datareg 1 2020-07-24 08:00:00 2 2020-07-24 08:30:00 3 2020-07-24 08:45:00 4 2020-07-24 09:00:00 5 2020-07-24 13:00:00 I need a query that returns the AMOUNT of records…
-
0
votes1
answer27
viewsSelect a date field by extracting only the month and year
I need to mount a Query that selects the sum of the vacant amount of each month in a period of one year. In case there would be several dates within each month that would have vacancies, which…
-
0
votes1
answer60
viewsInsert based on a select, with NOT EXISTS validation with multiple records with Postgresql
Could someone help me, as a select-based Insert would do so by checking if the value already exists , with multiple values ? this way this working, however I would like to insert more than 1 record…
-
0
votes0
answers85
viewsProblems with Stored Procedures on Laravel 5.6?
I’m making a select in a procedure, but I can’t page because the result returns array: DB::select('EXEC PR_MONITORAMENTO @FUNCAO="S2", @ID_CD_INTERNACAO='.$ID_INTERNACAO.',…
-
0
votes2
answers33
viewsQuery SQL listing shopkeepers by id and status
Personal I have a table where I list purchases of customers, in this table I have information as the id of the shopkeeper and the status of the order, this status goes from 0 to 6, however I would…
-
0
votes2
answers538
viewsUpdate in year without changing the month, day and time
I am trying to make a script to change the year of a table record where the dta_shutdown field has the date in the format of 08/25/2091 13:06:00 in Oracle database. I need to change the year 2091.…
-
0
votes1
answer916
viewsWhen is it valid to use XACT_ABORT() in a script that is already using TRY/CATCH?
Assuming the following code: /* DROP TABLE #Teste; CREATE TABLE #Teste(id INT); INSERT INTO #Teste VALUES(1); CREATE TABLE LogErros(id INT IDENTITY(1,1) PRIMARY KEY, nomeTransaction VARCHAR(100),…
-
0
votes2
answers355
viewsStoring multiple values in the same column of the database, how much is it worth?
I realize that many people encounter this doubt at some point in their development, "Do I put comma-separated values in the same column? Or create an auxiliary table?" Both questions have their…
-
0
votes1
answer300
viewsSQL - Insert random values into a table
Hello I am trying to insert random values in the columns but without success. I tried that but I got nothing. Someone who can help please. Declare @NovosID int SELECT @NovosID=NovosID FROM…
-
0
votes0
answers38
viewsHow can I update Mysql to an entire column if another one is doing it?
Somebody smart can help me with this? I have a table in Mysql named "Sellers" and I wanted all the rows in a "seller_image_s3" column to receive an update of "1" if the "seller_image" column is…
-
0
votes1
answer522
viewsProblem using parameter in Preparedstatement
I wonder if there is any problem in using the variable "parameter" after "AND", because when I tested putting the column name directly in SQL it worked and when I try to pass the column name with…
-
0
votes1
answer35
viewsError 1064 in Mysql Workbench
I wrote the following code for the college database class: CREATE DATABASE estoque; USE estoque; CREATE TABLE produtos( /*o erro ocorre aqui nesse parêntese*/ INT codP, CHAR (20) nomeP, FLOAT…
-
0
votes1
answer1101
viewsConnection being refused
Following this tutorial of Vedovelli about Ode with restify and mysql, I implemented on the server with pm2. Only after a few days the connection began to be refused Is showing that message: errno:…
-
0
votes1
answer32
viewsSelect Same Field
Hello! I need to make an SQL that gives me the result and I wish in the same line. Today SQL is skipping a line. I need you to stay on the same line. select c.empresa, p.nome, (select…
-
0
votes1
answer30
viewsSelect Chained between two tables using criterion the field of the first
Good afternoon, great masters. Here’s the situation, I need to get you out d12400 all field results nrentg in which the field dtentg be = '13.10.2020', to search in the table d12410 the fields that…
-
0
votes2
answers729
viewsPower BI - Oracle SQL Query
Hello, I am trying to get data in Power BI via Query on an Oracle DB and is showing the following error. Cannot establish connection Details: "Oracle: ORA-01843: not a Valid Month" SELECT DISTINCT…
-
0
votes0
answers38
viewsHow to make a history
Hi, I have a question and I don’t know how to begin to resolve it. I’m using the Asp.net mvc and I have to create a history table, where it makes a copy of a certain part, even if I delete the…
-
0
votes0
answers15
viewsI’m having problems with Exception in thread "AWT-Eventqueue-0" and I’m not getting it right
I need to put information from a database into a Jtable and I’m not getting out of that internship and I can’t find it on the Internet. In this project I need to register residents in an Sqlite,…
-
0
votes1
answer3728
viewsPHP Warning: PHP Startup: Unable to load Dynamic library 'pdo_sqlsrv.so' - php7.+++
Upon completion of PHP7.++ got the following error after performing all steps of SQL Server PDO Driver Configuration Tutorial for php, Restart apache2: PHP Warning: PHP Startup: Unable to load…
-
0
votes1
answer68
viewsHelp with Join in Mysql
I found several questions/answers about John on the site, but I still can’t create the command I need. What I need is the following: I have the following tables: item (I have two entries) id…
-
0
votes2
answers49
viewsSQL Latest Record FROM segnda table by Id
I have two tables (Opportunity and Stage). I need to pick for each Opportunity the table row Stage where the StageTypeId is the same as input parameter. Table Opportunity Id, etc Table Stage Id,…
-
0
votes1
answer31
viewsQuotation Factor
The SQL below returns me quotation value, I need to find the quotation day factor that boils down like this: SQL SELECT SIMBOLO, CONVERT (VARCHAR(10),DATA,103) as DATA, FATOR FROM GCOTACAO WHERE…
-
0
votes0
answers17
viewsIn which cases is Primary Key NONCLUSTERED more advantageous?
Good afternoon, you guys! I was researching about Primary Key Clustered and found that answer: "The difference that actually exists is between the fields of the type NONCLUSTERED clustered clusters.…
-
0
votes0
answers580
viewsSQL - Align Column Values to Right
Hello! I wonder if by means of an SQL sentence there is any possibility of aligning the values of the columns to the right. Here is an example below that I can do via C#, but I wanted to do the…
-
0
votes1
answer74
viewsSeparate return from a table to a Timeline
I am creating a Timeline where there may be more than one user update per day. I need my return sql to already compare the dates and I can separate $sql = "SELECT * FROM tb_timeline JOIN…
-
0
votes0
answers24
viewsHelp with a lower grade grade grade grade
Create a program that lists the discipline with the lowest grade point average. I can’t pull and the lowest grade point average and I hit a lock. I made this code so far. I really appreciate the…
-
0
votes1
answer23
viewsInformation is off the table in while
Only the first information from tbody is shown the others appear however in lines outside the table. What may be making this happen? follows below the code snippet: <?php } }else { $sqle =…
-
0
votes1
answer23
viewsSQL - How to list only records that have more than one daughter table
I need to list the names of employees who have two or more children (are listed twice or more) in the following select, but have no idea how. select f.NomeFunc as "Funcionário", d.NomeDep as…
sqlasked 4 years ago Jessé Anthony 1 -
0
votes0
answers46
viewsconvert sql to typeorm
I’m trying to convert this code sql for typeorm, thanks no more. select * from Product join Category on Category.id = Product.category_id where(Category.title = "Celular");…
-
0
votes0
answers32
viewsRead a BLOB field and convert RTF
I need to read a BLOB field where there is a text in RTF and convert to another format not being RTF in a select. select utl_raw.cast_to_varchar2(dbms_lob.substr(obs)) from entidade anyone knows any…
sqlasked 4 years ago Andrey Schemel 174 -
0
votes1
answer42
viewsQuery a column using the output from another column
Suppose I make the following select: select "nome", "quantidade", (quantidade * 2 - 5 % 3) AS numero ((quantidade * 2 - 5 % 3) * 5) AS segundo_numero from "tabela" How do I use the field numero…
sqlasked 4 years ago Vitor Ceolin 464 -
0
votes1
answer619
viewsDistribute values in column, SQL
I am extracting data from a table with the following query: SELECT [nu-cpf] as CPF, [nome segurado] as NOME, '' as IdentificacaoCliente, '' as CodigoBeneficio, CONCAT([nu-ddd],[nu-telefone])…
-
0
votes0
answers337
viewsInner Join problems on Dapper
I have the following problem, when I make a Inner Join in 3 tables the Dapper does not bring me all the columns of the 3 tables but only the one of my father table Inner Join ( or is the first table…
-
0
votes1
answer69
viewsMYSQL returns OK
Good evening friends, Can anyone tell me why the query below returns OK? SELECT Count(*) as Dias_uteis FROM Owner.dias_uteis d WHERE d.data_util BETWEEN (select ts.creatión from Owner.tabela ts…
-
0
votes0
answers10
viewsDatabase error php mysqli_fetch_array() expects Parameter 1 to be mysqli_result, bool Given in C: xampp htdocs delete.php on line 36
i am making a database deletion code in php, and ta giving this error on line 36 require "conecta.php"; $flag=false; $conecta= mysqli_connect("localhost","root","","cadastro"); $consulta = "SELECT *…
-
0
votes1
answer68
viewsRegistration is not being sent to the database
When I use 'Insert into noticias set ? ', to register in the bank, it is simply not registered Model: module.exports = function() { ... this.salvarNoticia = function(noticia, connection, callback) {…
-
0
votes3
answers51
viewsI can’t get average
I’m unable to sum up the qtd_itens_purchase with Count cod_person. The query runs normal, frequencybuys the displayed result is the same as the amount of items that comes from "qtd_itens_purchase".…
-
0
votes1
answer30
viewsConcatenate lines into one
Good afternoon, I need to unify some data, when I bring this so: id 2017 2017-LOJA 2018 2018-LOJA 1 n n s s 1 s s n n Would like so: id 2017 2017-LOJA 2018 2018-LOJA 1 s s s s consultation I made:…
-
0
votes2
answers67
viewsHow to calculate the value of two subquery in Oracle SQL
How to calculate two subquery on Oracle? Could you explain to me how I sum up VALOR_1 + VALOR_2? SELECT COL1 , (SELECT SUM(TAB1.VLRTOTAL) FROM TABELA TAB1 WHERE TAB1.ID = TAB3.ID) AS VALOR_1 ,…
-
0
votes1
answer49
viewsDisplay message as per condition in query
I’m making the difference between dates when the column designacao_circuito are equal and the difference (days) between the dt_hr_fecom is <= 10, I need that in the column Reinc_10_Dias write…
-
0
votes2
answers84
viewsUnion All specify select no order by
I have ONE test table and I’m doing a Union All and I want to sort by date but not sort by the first select before Union All which would be a headline. I would like to order only the data of the…
-
0
votes1
answer42
viewsDo not bring duplicates with a certain condition in a SELECT
I need to build a query that removes duplicates from a custom column (concatenated) if a given column is X value. For example: SELECT emp, cod, vev, gru, concat(cast(emp as char(20)), cast(cod as…
sqlasked 3 years, 11 months ago Fernando Fefu 301 -
0
votes1
answer46
viewsUpdate of holidays in SQL Server table
I have an SQL Server table called Dm_tempo. Its fields are: DtRef AnoRef MesRef DiaRef MesExtenso CodDiaSemana SemanaNumero IndFeriado And already have in it days marked as holidays (in this case,…
-
0
votes0
answers27
viewsHow to insert data into a specialized table?
I have two tables, according to the following logical design: Person(CPF, RG, Name, Address, City, State, Birth date) Client(CPF, Telephone) CPF references Person There are other specializations of…
-
0
votes0
answers40
viewsI can’t compare an arithmetic mean, so I can use select
I’m using postgresql to do the select of an attribute called val_unit of a name table produto. I use having avg(val_unit) > val_unit or where avg(val_unit) to select only the val_unit that stays…
-
0
votes3
answers153
viewsGet the sum of authors' books with Mysql
I’m starting with sql and I’m trying to get the sum of all books of each user in the cart table, but I’m not getting. drop table if exists carrinho_de_compras; drop table if exists usuario; drop…
-
0
votes2
answers1251
viewsForeign key for different tables (Mysql)
When executing the error query stating that it is not possible to create the Foreign Keys, I looked in the documentation and did not understand right if this code is possible or not. create table…