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
answer43
viewsnot in the same table
Let’s say I have the table CON_CONTRATOS and in it I have con_customerId, con_vencimento among others. And I need to make a select that returns ALL contracts of a Costomer whose same only contract…
-
0
votes1
answer60
viewsDoubt SQL query via primary key in PHP?
I am starting in the PHP language, and need to return a simple query made in sql from a variable that receives the value typed by the user. Since, it will only display the primary key search result.…
-
0
votes1
answer153
views -
0
votes0
answers52
viewsFunction to return total sales
I have this function that returns me the amount of sales of a cnpj month to month in the year 2018, I would like if possible someone would help me implement a variable in this function, which takes…
-
0
votes1
answer68
viewsAverage SQL Cost
Hello. I need to present the average cost, the lowest cost and the highest cost of all products and present the total of verified products. The table I have is this: Does anyone know how I love it?…
-
0
votes1
answer57
viewsAdd values from a table
I have the following query: $qrysel = "select * from won_auctions w left join registration r on w.userid=r.id where payment_date!='0000-00-00 00:00:00'"; This query will show a list of users of the…
-
0
votes1
answer100
viewsSubtraction between two fields of the same value does not give zero-SQL Server
Someone could explain to me: I made a Join between two tables. Both bring the same value in their fields. And when subtracting one value minus the other, it does not give zero. As this is possible?…
-
0
votes2
answers784
viewsSelect current date comparison with exact date 1 month ago
I made this select that returns me the amount of records in the last 24 hours select count(*) from registros where registry_date >= NOW() - interval '24 hours' I need a select to compare the…
-
0
votes2
answers84
viewsHow to work the return of a select max query?
I will be brief: When trying to work the values of a query that uses MAX, I get the error: Use of Undefined Constant protocol - assumed 'field name'. Table: Select: $atestados = $conect -> query(…
-
0
votes1
answer733
viewsHow to update a View?
I have a table where you store trucks in and out. In this table there are two fields of the type Date, I want to update the data of these fields. I’m using the select below. UPDATE…
-
0
votes1
answer125
viewsI cannot find Login error
am logging in, but even when I put the data of a registered user appears invalid data. login.php <?php session_start(); require_once "Classes/UsuariosDAO.php"; require_once…
-
0
votes1
answer239
viewsString size in PL/SQL
CREATE OR REPLACE FUNCTION TamanhoString(texto char(100)) RETURN NUMBER IS tamanho NUMBER; BEGIN tamanho := LENGTH(texto); RETURN tamanho; END TamanhoString; I need to create a function that…
-
0
votes1
answer74
viewsError in running Function SQL Server
I have a database proof today and I’m practicing functions with old exercises only I’m getting an error when I run the function. tables set language brazilian; CREATE TABLE pedido ( nr_pedido…
-
0
votes1
answer413
viewsHow to use pseudonyms in queries using Aliases along with Mysql?
I would like to be able to use the Alias 'AS' along with mysql without having to do query alignment, that is, I want the secondary queries to be named to use them in the main query, it is possible?…
-
0
votes1
answer182
viewsLimit amount of SQL information
How can I limit the number of rows in my SQL table?(other than with limit in select, it’s not like query) ex. I have to have a maximum of 10 information in the table, but it is not limited, if 30…
-
0
votes1
answer262
viewsSQL group by returns duplicated POSTGRESQL
My query SQL is returning multiple Rows with the same id follows: SELECT distinct (c.nome), c.id, c.email,c.telefone1,c.telefone2, SUM(a.valor) AS "valorDaCompra",u.id AS "idLoja",u.nome AS…
-
0
votes1
answer108
viewsDouble INSERT no stored
Currently what I have is basically this: CREATE PROCEDURE `Teste`( IN `@valorX` INT, IN `@valorY` INT ) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER INSERT INTO tabelaX(colunaX) VALUES…
-
0
votes1
answer134
viewsSelect from column B if field selected in column A is null
In a consultation SQL was trying to work out a way to select a value from another column B if the selected column value To is null. I first made the following query: SELECT…
-
0
votes2
answers259
viewsInsert Select Sql Server
Connection and Historico_ligacao I have a script which copies all data from the table Ligacao for Historico_ligacao. When I compare the data between the theban, the table historico_ligacao is…
-
0
votes2
answers59
viewsSELECT Cursor using top1
I need to return only the highest value of one of the lines below, taking into account that I also need to submit the order code. I tried to rotate via cursor but without success. The cursor would…
-
0
votes2
answers32
viewssql return php data
$hoje = date('d'); $data_hoje = "SELECT * FROM vendas WHERE dataCompra = now()"; $result = mysqli_query($conexao, $data_hoje); while($linha = mysqli_fetch_assoc($result)){ if($linha['dataCompra'] ==…
-
0
votes2
answers43
viewsselect search in database with repeated records
I’m making a select in my bank, whatever, Postgres, and more records are coming.. For example, id_pessoa comes a 10 more record than should come.. SELECT pac.cns, pac.cns_responsavel,…
-
0
votes2
answers52
viewsSQL/LINQ vs. Data to feed
I’m trying to generate a query in VS2015 with Linq (here, I exemplified in SQL, to speed up my tests right in the database) that returns the data grouped and counted from 6 months ago, it happens…
-
0
votes1
answer123
viewsSql does not return column name
I have two tables a TEAM another MATCH_DETAILS. The table TEAM has the spine id and is a primary key. I made two table reports TEAM for MATCH_DETAILS. In the MATCH_DETAILS assumed as foreign key…
-
0
votes2
answers1789
viewsDivision in the sqlserver
I am using SQL Server 2008, I would like to split 50/100 for example and return me 0.05. However it returns me 0, follows what I tried to do:…
-
0
votes1
answer197
viewsSearch item result in same line separated by comma
I have a select that returns the risks (work safety) in several lines, I would like the item "T4.RIS_RISCO" to appear in a single line separated by comma, can anyone help me?? have basic…
-
0
votes1
answer920
viewsIt takes a long time to query in mysql
Hello friends I’m having a hard time finding what is wrong in my selection code (SELECT) in mysql, this taking more than 70sec do not know why. Someone there to help me please? Code: SELECT…
-
0
votes3
answers156
viewsCondition in a select
I need to create a SELECT which contain only records of a value x onwards. For example, return only movies with number of copies greater than 5 My Select router.get('/filmes', (req, res) =>{…
-
0
votes1
answer49
viewsData manipulation in the programming or database
Assuming I need to handle a given example I get weight and height from a user. I want to calculate her BMI to enter into the database. This BMI calculation must be done in a function in the code, or…
-
0
votes1
answer41
viewsReturn amount of dependents per employee
I need to select the Plate, the Employee Name and the Number of Dependents of each Employee, but the result of this query is showing the amount of dependents only for the first employee, and I need…
-
0
votes1
answer372
viewsCreate select for a PHP table
I’m having trouble creating the select to later use in a table. The mandatory SQL tables are the following: “Aluno” (**PK:** id, numero, nome), “Area” (**PK:** id, nome), “UC” (**PK:** id, nome,…
-
0
votes0
answers255
viewsCalling data from a form on the same HTML page
I want to call data already inserted in a form and use them on the same page HTML in which I will use them in a consultation SQL. Because depending on the number of municipalities will be generated…
-
0
votes0
answers118
viewsHow to reload a PHP page via Javascript?
I own a page in PHP and that records the dodos of a form via JSON, below the script: Index.php <?php include '../includes/config_db.php'; include '../includes/functions.php'; include…
-
0
votes1
answer1060
viewsERROR CODE 1215 - You cannot add foreign key
Table 1: Table 2: Commando: ALTER TABLE extras ADD FOREIGN KEY (login) REFERENCES usuario(login); Answer: Error Code: 1215. Cannot add foreign key constraint Cannot find an index in the referenced…
-
0
votes1
answer130
viewsMysql query to display records not linked to a particular company
I need to create a query on SQL. I have three tables: TABELA 1: EMPRESA emp_codigo (chave primaria) emp_nome TABELA 2: PALAVRAS_CHAVE pal_codigo (chave primaria) pal_nome TABELA 3: VINCULO…
-
0
votes2
answers462
viewsBring today’s date records up to 1 month ago SQLSERVER
How do I get today’s date records up to 1 month ago on SQLSERVER? I know that for example, with 7 days, use GETDATE()-7. But and for 1 month, as would be?
-
0
votes1
answer51
viewsGet sql that triggers a Trigger before update
I have a Trigger before update very simple, I would like to take the sql that fires that Trigger. CREATE OR REPLACE TRIGGER atualiza_subelemento BEFORE UPDATE ON tb_material FOR EACH ROW BEGIN IF…
-
0
votes2
answers1597
viewsPostgresql Error: "ERROR: there is no Unique Constraint matching Given Keys for referenced table "address""
created the table Address and Client, as follows sql: CREATE TABLE ENDERECO( Logradouro VARCHAR (50) NOT NULL, CEP VARCHAR(50) NOT NULL, Numero INT NOT NULL, Complemento VARCHAR(50), Cidade VARCHAR…
-
0
votes3
answers392
viewsHow do I find the first Tuesday of a month?! (SQL)
I’m performing the following exercise: The tables are as follows: : I already have the following code: SELECT NOME FROM CLIENTES C,VENDAS V, LIVROS L WHERE V.CODIGO_CLIENTE=C.CODIGO_CLIENTE AND…
-
0
votes2
answers137
viewsProblem sending input value (which is updated in a While) to another page via POST
I have a looping loop while which creates fields according to the number of customer municipalities. I need to pass the variable codmunicipio via method POST to be inserted into the database on…
-
0
votes2
answers597
viewsJoin column data online - SQL Server
I have the following situation: Usuario_A telefone1 Usuario_A telefone2 Usuario_A telefone3 How can I make so that when I make a select, I have the following output:…
-
0
votes2
answers112
viewsSQL: Compare between 2 columns and return only 1
I have a table of clients that includes clients PF and PJ. In this table, if the client has CPF has no CNPJ, if CNPJ has no CPF. I need a query that checks which of the two columns is not null and…
-
0
votes1
answer279
views -
0
votes1
answer80
viewsDelete result with JS and PHP
I have a js script to delete sql results with PHP and JS... LINK <a href="javascript:;" onClick="deletar(<?php echo $exibe['matricula']; ?>);"> JS function deletar(matricula) { if…
-
0
votes0
answers37
viewsHow to show NULL in fields where the condition is not satisfied in SQL
I have this Input table (p): EmployeeID EventId EntityId EnterDate 11111 100 1 2:54:11 11111 100 1 2:54:43 11111 100 1 2:56:03 11111 100 1 2:56:35 11111 100 1 2:58:51 And this Output table (q):…
-
0
votes1
answer45
viewsis_numeric is safe to select?
I am developing an application with PDO, and I normally use the bindValue() to execute the SELECT's, but I am developing an application that receives a variable that contains numbers and comma,…
-
0
votes1
answer72
viewsSelect the value of a field depending on a date
I have a table with the fields DT_FIMCALCULO, VL_DEPREREVVIDAUTILACUMULADA e CD_SEQUENCIALBEM. And for each CD_SEQUENCIALBEM I have several DT_FIMCALCULO each with a VL_DEPREREVVIDAUTILACUMULADA…
-
0
votes1
answer689
viewsHow is the text of the python-kivy text_input used?
I’m having trouble using text_input text to store in the database. Python code: from kivy.app import App from kivy.uix.screenmanager import ScreenManager, Screen from kivy.core.window import Window…
-
0
votes1
answer372
viewsIdentify the change of record in a time table?
I am working on a table that keeps the history of some people, and I need to identify and display the lines that have been modified in a certain column. See example: --Tabela HistSituacaoPessoa id |…
-
0
votes1
answer42
viewsHow can I pick up items not viewed?
Use the following select to pick up items already seen: $sql = $conn->query("SELECT * FROM views b, news a WHERE a.status = 'true' AND a.id = b.id_news AND b.ip = '$ip' ORDER BY a.id DESC LIMIT…