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
votes4
answers79
viewsFind names in 2 different tables
I want to search in 2 tables of the database where the name equals the variable $nome. I would not like to join data as if they were FK, but pull all the information from these tables (other…
-
0
votes2
answers79
viewsMysql query using JOIN
Hello! I have the following database: I would like to make a query where I can search for example the teacher x that is related to the student y and z but not the student w. However when performing…
-
0
votes1
answer60
viewsError using ALIAS in select
In the select below, I would like to use the alias novonome in the second column (instr). select substr(titulo, 1, 20) AS **novonome**, instr(**novonome**, ' ')+1 from conteudo; But I get the…
-
0
votes1
answer350
viewsPostgresql connection with JDBC in eclipse
Appears on the console: java.sql.SQLException: No suitable driver found for jdbc:AulaFBD://localhost:5432/TrabalhoFBD at java.sql.DriverManager.getConnection(DriverManager.java:689) at…
-
0
votes1
answer302
viewsHow to escape quotes from a json key in Postgresql?
I have a function that receives JSON’s, it turns out that it is possible for the user to put as follows: Normal: '[{"nome":"João Carlos"}, {"nome":"Maria Silva"}]' Problem: '[{"nome":"João -…
-
0
votes2
answers68
viewsError 102 in Openquery
I’m making this mistake: Incorrect syntax next to@SQL_LINKED.. Error 102. SQLSTATE 42000. Severity 15. Msgstate 1. Line 78. When trying to run this script : SET @SQL_LINKED = 'SELECT CAST(v.produto…
-
0
votes2
answers80
viewsGenerate an array within XML in sql server
I have the following problem: I am running a Procedure in Sql Sever that generates an XML through the XML PATH command, however, one of the fields is an array, what I got was this: This select is…
-
0
votes1
answer99
viewsHow to change a Primary key to Auto_increment Constraint
I created the following table create table if not exists cursos( nome varchar (30) not null unique, descicao text, carga int unsigned, totaulas int, ano year default '2018' )default charset = utf8;…
-
0
votes1
answer80
viewsError variable stmt of type Statement
I’m trying to run the table, but in netbeans it keeps alerting the error in the Executequery line. Symbol: method executeQuery(String) Location: variable stmt of type Statement The error is…
-
0
votes0
answers380
viewsThere has been a violation of the referential integrity restriction
I am getting this error every time I try to update an object in my SQL database via Entityframework, the error is as follows: A reference integrity constraint violation occurred: Property values…
-
0
votes1
answer96
viewsGet sales average for a given month
I would like to take the average sales of the month by product description and not by date with day, month and year, but I don’t know how to get. SELECT AVG(vend_qtde) AS qtde_vendas from tb_vendas…
-
0
votes2
answers53
viewsDoubt about Querys
I am trying to create a view to return the query of a Query. My problem is that I wanted to return values for each product and is returning the same value for the products. SELECT B.ID_Caso,…
-
0
votes1
answer87
viewsMultiple SQL query
I’m not very experienced with SQL language, as I could make a query work this way: SELECT *, ( SELECT marca.* FROM marca WHERE marca.id = produtos.id ) AS nome_marca FROM produtos WHERE id = 5 What…
-
0
votes3
answers1410
viewsDisplay more than one information in the same table with PHP and MYSQL
I would like to display in the table the information of the enrolled student and also the courses that he is enrolled. Final result that I would like to be shown: Nome Aluno | Telefone Aluno |…
-
0
votes1
answer38
viewsSqlquery - Some Duplicate Records
Guys, in the query below is bringing the following way. UsuID Consultor Tentativa 1 Abertos 95093 Gabriela 96 However, it was to bring in the following way: UsuID Consultor Tentativa 2 Abertos 95093…
-
0
votes0
answers81
viewsIntegration between two databases
I have an idea to integrate two databases, at one point I have the database Postgressql with system A and on the other side a bank Firebird in system B. For example: I recorded a client on system A…
-
0
votes1
answer516
viewsReplace SQL SERVER between columns
How to replace between columns in SQL SERVER. For example, given the table below: COLUNA_A | COLUNA B | COLUNA_C A 123 casa I tried to run the query: SELECT REPLACE(COLUNA_C, COLUNA_A, COLUNA_B )…
-
0
votes1
answer146
viewsFriendship system
I’m making a friendship system (look at the img) In users shows all the people I can add as friends, I want to remove from the list of users all the people who have already sent me friend request…
-
0
votes0
answers177
viewsGenerate random number with repeat rule
I need an SQL command that generates a random number between 1 and 11, and that for number 1 is generated more often than others. Currently I use the following command: FLOOR(1 + (RAND() * 11)) It…
-
0
votes0
answers77
viewsData Flow Task generates blank Excel file - SQL Server Integration Services
I have a process in SSIS that takes information from a table and exports it to an xlsx file. It happens that, when running Job by SQL Server Agent, often the file is generated blank, even if it has…
-
0
votes1
answer152
viewsGroup By SQL Server function
I’m a beginner in SQL Server, would like a help to understand the function Group By in a simple way. Both your concept and the way to use... for those who can help me thank you already!…
-
0
votes1
answer363
viewsHow to add XML encoding tag
How to add XML encoding clause <?xml version="1.0" encoding="UTF-8"?> When you generate XML via FOR XML PATH as an example below: SQL query: WITH XMLNAMESPACES (DEFAULT…
-
0
votes1
answer597
viewsI cannot create the connection to the database in my php file
I’m trying to connect with the bank but only appears this error: Fatal error: Uncaught Pdoexception: could not find driver in C: xampp htdocs PDO Example-02.php:3 Stack trace: #0 C: xampp htdocs PDO…
-
0
votes1
answer185
viewsUsing Count with select all
I am wanting to make an sql counting the records with duplicity: select produto,matricula,data,fornecedor, count(*) from tb_teste group by produto,matricula order by fornecedor This way of the…
-
0
votes2
answers53
viewsUpdate data associated with a specific name in a PHP and SQL database
UPDATE: This question will be long - notice that I am very inexperienced in PHP. I have been (trying) to create a web page that can access a database created in Phpmyadmin in the last few days, this…
-
0
votes1
answer48
viewsHow to get from last record to first
I have these names on my chart: nome ----- A B C D E F If I do: SELECT nome FROM tabela he will return me "A, B, C, D, E, F". I’d like you to return me backwards, from the last record to the first.…
-
0
votes1
answer328
viewsHow to get value from a SQL in php?
I have the following code <?php $buscaValorTotalSaldoInicial=$pdo->prepare('SELECT SUM(valor) AS vTotal FROM saldo WHERE data=:data AND empresa_idempresa=:id_empresa');…
-
0
votes1
answer795
viewsDivision between values - Query SQL Server 2012
Guys, in the query below, is bringing the following way. Ano Mes Horas total_horas 2018 1 107 766 H 2018 1 225 766 H Therefore, I want you to bring in another column the division of the column…
-
0
votes1
answer720
viewsSqlite error: Foreign key Mismatch (fk incompatibils) when trying to make an insert
I’m trying to create a Associative Entity (N:N) in Sqlite like this: [ Pet --< Vacinapet >--- Vaccine ] And, here is the code of my Associative Entity CREATE TABLE VACINAPET ( vp_data TEXT NOT…
-
0
votes2
answers495
viewsConcatenate SQL Server
I have the following appointment: SELECT UPPER(admatribuido) AS [admAtribuido], Count(admatribuido) AS [quantidade_admAtribuido] FROM ##tmp WHERE Month(dataabertura) = Month(Getdate()) AND…
-
0
votes1
answer769
viewsRegister multiple records using the same form
I have a customer registration form where it is possible to register one customer at a time, how do I register two clients at once using this same form? Tested put one more input, but only register…
-
0
votes2
answers271
viewsUPDATE with two conditions
I’d like to make a UPDATE where I have two conditions; I would like to join the two in one, if not one is the other. FIRST : UPDATE RLT005 SET CtrDatBaixa = '2018-12-15 00:00:00' WHERE CtrDatBaixa…
-
0
votes1
answer290
viewsDelete multiple lines from SQL Server that have the same text snippet?
To test my forms, I ran multiple fills with the word "test" in the fields. Now I wanted to clean the BD, but I’m having difficulties to delete several lines with the same text snippet "test" I am…
-
0
votes0
answers32
viewsget_where to PDO
I want to change get_where to mysql or PDO, but I don’t know! Help ...! public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL) { if ($table !== '') {…
-
0
votes1
answer76
viewsPHP is not returning query data
Hello, I am using the following code to return regions: $query = 'SELECT * FROM Regiao'; $json = array(); $result = mysqli_query ($conn, $query); while($row = mysqli_fetch_array ($result)) { $regiao…
-
0
votes1
answer24
viewsError writing in SQL table from Windowsform
I’m trying to write several fields in a table from a Windows Form App. Some of these fields are Foreign Keys from other tables. If the fields have values, the SQL statement is executed but if they…
-
0
votes0
answers97
viewsimplicit Conversion (varchar to varbinary) not allowed, use the CONVERT
I’m trying to make a system that obtains images and saves them in a specific database, but I can’t solve this error (I’ve already applied CONVERT to SQL but it hasn’t solved). (Error area) //Aqui…
-
0
votes1
answer265
viewsCompare two totals using LEFT JOIN in Mysql
I have two tables: Venda and ProdutosVenda, where the table Venda has a field named 'Id_key' and the ProdutosVenda, that will store the products of this sale, has a field called 'Id_referencia',…
-
0
votes1
answer732
viewsError creating Foreign key
I am creating two references of Foreign key pointing to two different tables, however I am getting error in creating one of them. There are no Primary or candidate Keys in the referenced table…
-
0
votes1
answer98
viewsRun PHP within Javascript Function
I have the following function being called by onclick, the problem is that I can’t use Javascript variable in php, someone has an idea of how to do this function? Function fila(id){ var idBanco =…
-
0
votes2
answers111
viewsType convection error
Trying to record in a sql table an image, its name and description and some foreign keys to allow me to search later. On execution I get error of string conversion for Int 32. But all fields in the…
-
0
votes0
answers51
viewsDoubt in sql, Join between tables and results
I am making a Join between tables, where I need to return all the rows of the first table, however I use a Where to limit in the field of the date, so I end up limiting my result to only the lines…
-
0
votes1
answer551
viewsIn PL-SQL how to partially add a value?
I have to add the value partially the values of a category (goes the code below) DECLARE --VARAVEIS CURSOR CPRODUTO IS SELECT * FROM PRODUTO_TESTE2; VPRODUTO PRODUTO_TESTE2%ROWTYPE; Vsoma real;…
-
0
votes1
answer50
viewsSQL grouping information
I have the following sql statement: SELECT * FROM TB_CADPRECO WHERE MAT_GESTOR = 123 AND UF_PRODUTO LIKE 'PR' AND TIPO_CAMPANHA = 5 AND DT_CAMPANHA = '01.08.2018' UNION SELECT * FROM TB_CADPRECO…
-
0
votes0
answers127
viewsCompare values of two tables in a Procedure
I have an application that lists in a grid files that are registered in the table Scf_documentprocessocompra However, now I need to list only if this file also exists in the table SCF_ARQUIVO_UPLOAD…
-
0
votes1
answer697
viewsHow to perform a search disregarding Firebird special characters in the WHERE Clause
I’m making a View and Clause WHERE it does not accept a filter of this 'Temporary' only if removing the accent Ex: 'Temporario'. CREATE VIEW VWORDEMPRODUCAO ( CODEMPRESA ) AS SELECT F002 AS…
-
0
votes2
answers39
viewsHow to correctly display data from a commemorative date table
Sections of the table The intention is to bring the records of the commemorative dates in an interval of month and day. Example: I want to bring the commemorative dates that are between 15 January…
-
0
votes0
answers294
viewsError while displaying message in PL-SQL
Code DECLARE BEGIN FOR I IN (SELECT * FROM PRODUTOS_TESTE2) LOOP DBMS_OUTPUT.PUT_LINE(I.codigo|| ' - ' || I.categoria || ' - ' || I.VALOR); END LOOP; END; Error message: Relatório de erros -…
-
0
votes0
answers684
viewsOracle error ora-06550 pls-00103:
I have this PL-SQL code: /*1. Criar um bloco PL/SQL anônimo para imprimir a tabuada abaixo:*/ DECLARE VN CONSTANT NUMBER(2) := 5; BEGIN FOR i IN 1..1O LOOP DBMS_OUTPUT.PUT_(VN || ' X ' || i ||'='||…
-
0
votes2
answers26
viewsEnum date trucate
I have the following query: INSERT INTO celulas ( diaReunioes ) VALUES ( 'Terça' ) You’re making the following mistake: Data Truncate for column 'diaReunioes' at row 1 This field in the table is:…