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
answer58
viewsVoid Checkerror Oracle x IIS
Well, due to the exhaustion of my attempts to find the error, I’m going to try to get a light here with you. I apologize now if the error is too generic and does not have the necessary information.…
-
0
votes1
answer98
viewsSubconsultas Select
My bank is like this: cd_cliente | nr_ddd | nr_telefone 30 | 11 | 25622791 30 | 11 | 25622791 My select is so: "SELECT * FROM tb_telefones WHERE nr_ddd="+ddd+" AND nr_telefone="+telefone+""; It…
-
0
votes1
answer162
viewsWhat is the meaning of the "indexing equal or removed" error in Mysql?
I am working with small relationships and I realized that in a state table in which I related the field id the table país[id] I get this error message or alert, I’m not sure. Already in a table…
-
0
votes1
answer783
viewsReturn with different values in JSON / PHP
Scenario: I have a query made in PHP and need to return it to my iOS app in JSON format. But when doing some tests, in the browser, I noticed that when using the function echo…
-
0
votes1
answer526
viewsHow to set a default value created by the user in the creation of a table (SQL Server)?
I created a default value for my database: CREATE DEFAULT [dbo].[zero] as 0 But I cannot create a table using this default value created. How do I set this value when creating a table? For example:…
-
0
votes2
answers49
viewsInsert into the database according to the data found
I have a certain problem in "logic", where I must enter the records of two arrays in a table from BD. There I have the following situation: In the first if I check if the tabela_p does not contain…
-
0
votes2
answers51
viewsHow to do two checks in select
I have 3 selects in my code where: If the user enters the start date and the end date will show the data between them. If the user enters the invoice will show the data with this note. If the user…
-
0
votes1
answer487
views -
0
votes1
answer102
viewsHow to concatenate SQL statements?
$tarefa1 = "ALTER TABLE imovel DROP COLUMN CAMPONULL"; $tarefa2 = "ALTER TABLE imovel ADD ENDERECO VARCHAR(300)"; $tarefa3 = "ALTER TABLE imovel ADD COMPLEMENTO VARCHAR(3000)";…
-
0
votes2
answers289
viewsView grouped data
I am making a query in the database and I am having difficulties with data duplications, so far, this is my query: SELECT * FROM tec_postagens tp INNER JOIN tec_historico_status th ON…
-
0
votes1
answer551
viewsSelect products in a certain range of discounted values?
I’m trying to make a value filter for a virtual store, I have a product table, a stock and another for promotions. products CREATE TABLE `produtos` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `codigo`…
-
0
votes1
answer745
viewsProblem with accentuation when entering data in android Sqlite
I’m trying to give a insert in a table, but it gives syntax error. I believe it is because of the accent, but even searching can not solve. Log error: 11-19 00:34:52.959: W/Aquery(21157):…
-
0
votes4
answers964
viewsHow to do advanced data filtering across multiple fields?
I have a table from which I need to get results varying by certain user data: I need to return the rows where each column or hit with the respective user parameter or is empty (null). Consider as…
-
0
votes2
answers4604
viewsHow to insert by selecting from two different tables?
TABELA 1 - ID - IMOVEL - CODIGO - IMAGEM_G <----- nessa tabela este dado é vazio. - IMAGEM_P TABELA 2 - ID - IMOVEL <----- nessa tabela este dado é vazio. - CODIGO <----- nessa tabela este…
-
0
votes3
answers1715
viewsCreate a Trigger that runs whenever a product is deleted
How to create a Trigger that is executed whenever a product is deleted, performing the delete action in all batches related to the deleted product. Here’s my SQL code: create database provafinal;…
-
0
votes1
answer63
viewsSearch function for Sql Server
I wonder if it has a function or if it could be done with a select, search by e-mail field of a table. Example: select PPESSOA.EMAIL from PPESSOA where PPESSOA.NOME like 'ABNER FONTOURA C,RÊA'…
-
0
votes0
answers60
viewsAutomatically add line
I wanted an sql script or excel function that runs along the line and when find "Out of Compliance" add me a new line Name Food from Approved Source (C) Food Protected from Contamination (C) 16…
-
0
votes1
answer256
viewsAutomatically list products from different stores
I have a question in comparing prices of products from different stores, I have no idea which component to use or how to do this. The idea is to do something similar to Buscapé and Zoom (relate the…
-
0
votes2
answers2442
viewsHow to read and open files from a byte column in SQL Server?
My question is the continuation of this question: Link to the other question I managed to transform my file into bytes and insert it into a table in SQL Server, but now I want it from inside an…
-
0
votes2
answers2925
viewsConsultation in table with self-relationship
I have the following table containing self-relationship between the idcategoria and parent columns: idcategoria categoria pai 1 Camisetas 0 2 Regata 1 When an added category does not have a parent…
-
0
votes1
answer1278
viewsHow to put an SQL command in a variable
I have a following SQL command and I need to put it inside a variable in SQL. The code is this. WITH DB_CPU_Stats AS (SELECT SUM(total_worker_time) AS [CPU_Time_Ms] FROM sys.dm_exec_query_stats…
-
0
votes0
answers578
viewsCreating a PHP network panel
I am with the following doubt I have an oracle database with all the names and ip of the users. I would like to use this database in this code instead of using this array? <!-- painel.php -->…
-
0
votes1
answer161
viewsTrack #hash and create description from it [LOGICA]
I have come across this now and I would like to debate to make a logic. Well, nowadays it is used a lot the hashtags for everything in the main social networks, I almost never enter in Twitter and…
-
0
votes1
answer221
viewsInstruction Left Join in LINQ to entites
I tried to do a left Join on LINQ as follows: (from opr in db.Operacao join vol in db.Volume on new { VOL_CODBAR = opr.OPR_CODBAR } equals new { VOL_CODBAR = vol.VOL_CODBAR } into vol_join from vol…
-
0
votes1
answer1666
viewsI cannot create table in SQL SERVER
I have an instance of SQL SERVER installed locally where I am administrator, I can create Databases but I can’t create tables. Here is a photo of the error that SQL displays. More Some Details:…
-
0
votes2
answers175
views -
0
votes1
answer2862
viewsHow do you check if a view exists before you have it created?
Take as an example the following view: CREATE VIEW vw_types AS SELECT codigo AS code, nome AS description, abreviacao AS abbreviation, statusRegistro AS status FROM tipos How can I have it created…
-
0
votes1
answer1385
viewsError: table name specified more than Once
I created a column included in the app table, it works to record the purchase date of the app and I will have to update the old records with the user creation date. I made a query to solve the…
-
0
votes3
answers137
viewsPostgresql Query - How to do this?
How to make an SQL query in this table: ID Col2 Col1 -- ---- ---- 11 1 A 12 2 D 13 3 G 14 1 B 15 2 E 16 3 H 17 1 C 18 2 F 19 3 I To return this result: 1 A B C 2 D E F 3 G H I Is that even possible?…
-
0
votes1
answer336
viewsReturn last entry of each object in the database
I have two tables: monitor_carro id serial | setor_id | modelo | ano | placa monitor_evento id serial | lat | long | data | fkfuncionario_id | time | carro The monitor_event table has only one…
-
0
votes3
answers1060
viewsImplementation of generic CRUD
I have the following class CRUD that is generic: public abstract class CRUD { protected string tabela = null; protected object classe = null; public CRUD() {} public virtual void insert() { //código…
-
0
votes1
answer144
viewsWhy create the folder and not upload the image in sequence?
if ($_POST['salvar']) { $titulo = $_POST['titulo']; $conteudo = $_POST['conteudo']; $imagem = $_POST['imagem']; // titulo duplicado $sql = "SELECT * FROM noticias WHERE (titulo=:titulo)"; $stmt =…
-
0
votes1
answer230
viewsHow to view the SQL executed by php when using the functions "prepare()" and "execute()"?
Hello need to echo or print the SQL running from the function below. The goal is to visualize how the SQL will look when the values of "?" replaced. Does anyone know how to do this? public Function…
-
0
votes1
answer1722
viewsError Code: 1048, SQL State: 23000 Column 'colegiado_id' cannot be null
Hello, this mistake "[Error Code: 1048, SQL State: 23000] Column 'colegiado_id' cannot be null" happens when I try to run the SQL command below directly in Mysql: start transaction; INSERT INTO…
-
0
votes1
answer1412
viewsSearch by date range
How to create a query for the Oracle database by returning a list of orders according to a date range? Follows the code currently used: if (opcaoBusca.getSelectedIndex() == 0) {…
-
0
votes1
answer1468
viewsHow to mount a Select to join columns
I’m having a doubt I don’t even know if it’s possible: I would like to perform a select that joins two columns. Otherwise it would be: Person table with the cod_person fields - name - rg -…
-
0
votes1
answer98
viewsList table data and assign value to each of them (SQL)
Good morning! I would like to know how I do to list the data of a table and assign value to each of them! Example: Table: character Columns: ID and name I would like to take all the names that have…
-
0
votes1
answer302
viewsSyntax sql error
I’m trying to make an insert in the database but I’m having a syntax problem, I still can’t identify the error. $sql='INSERT INTO tabela ( nome, nit, rg, cpf, ) VALUES'; foreach($dados as $linha_bd)…
-
0
votes3
answers137
viewsProblems with WHERE IN (many records)
I need to assemble a query to search for records in table A, with table B record filter. Something like: SELECT * FROM tabelaA tblA WHERE tblA.coluna IN (1,2,3,...) The values contained in the "IN"…
-
0
votes1
answer112
viewsSwitch Case PDO does not display
Changed further inside the title yet, the case works but does not display the result. <?php $sql = "SELECT tipo FROM publicidade WHERE posicao='Lateral' ORDER BY RAND() LIMIT 1"; $stmt =…
-
0
votes2
answers248
viewsMerge two tables into a third table
I need to merge two tables imagem1 and imagem2 in a third table imagens with SQL. They have exactly the same structure but with 1 query I can’t write all the data at once, so I need to make 2…
-
0
votes2
answers170
viewsWhile isn’t stopping when he should
I have the following code: <div class="row"> <? $tag = mysqli_real_escape_string($connection,$_GET['categoria']); $result = $connection -> query("select * from produtos where tags like…
-
0
votes0
answers96
viewsDb2 query com between and Partition by
I need a help with this query below, it is not doing what I would like. It makes everything perfect. But when I use the between it returns an error. I would like a help on the query. SELECT UNIDADE,…
-
0
votes1
answer2545
viewsComparing data via Oracle Query
I have a table called Teste de aluno and a call Parametros I need to create a Query that compares if the test is in accordance with the Parameters The problem is that the tables are not 100% similar…
-
0
votes1
answer418
viewsHow to get bank reports through web application?
Where I work there are some procedures in the database (SQL Server 2008) that take hours to run and return large amounts of information that are always copied to a spreadsheet and sent to the end…
-
0
votes1
answer476
viewsSelect Format yyyyyy-MM-dd HH:mm:ss in MYSQL table column
Date 2014-12-01 10:52:38 2014-12-01 10:52:14 2014-12-01 10:51:57 2014-12-01 10:35:34 2014-12-01 10:23:17 2014-12-01 10:22:18 2014-12-01 09:03:49 2014-12-01 08:53:51 I have this column with these…
-
0
votes1
answer1057
viewsProblem saving result of an SQL query to a PHP variable
I have a SELECT to return the value of a table field funcionarionew, my idea is to save the result of SELECT into a variable and then insert the value of that variable into another table…
-
0
votes1
answer109
viewsAdd MYSQL constraint
I am using the following query: $sql = "SELECT * FROM `login` order by `account_id` ASC"; How do I add a constraint when account_id is 1 he "skip" and do not take the values of the line with…
-
0
votes2
answers9765
viewsHow can I use the UPDATE command between two tables?
I’m trying to update the field GRUPO table ESTOQUE value 1 (one) when the field NCM table EST_ADICIONAIS is equal to 21011000. Since, both tables have the field CODIGO with equal values. Use…
-
0
votes2
answers2226
viewsWhat better way to insert an array into the database
I would like to know how to best insert an array into a database table. I could use a foreach but I would like something performative because I will work with large number of data. foreach (var item…