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
answer90
viewsMysql update event
I asked this question yesterday, I got the answer I wanted, I’ll be straight and straight: I have the query: UPDATE users SET time = time - 1 time is the type int and receives as default value 0, in…
-
0
votes0
answers37
viewsI have a super extensive query when I try to insert into the database does not work, I don’t know why
$result = $db->query(" SELECT RES.morada, RES.espaco, SUM(DATEDIFF(RES.data_fim, RES.data_inicio)*RES.tarifa) AS pago FROM ( SELECT A.morada AS morada, A.codigo AS espaco,…
-
0
votes2
answers558
viewsMultiple if in one SQL condition
I’m trying to use 2 ifbut the result always returns empty, when I use only one if he will. SELECT aci_codigo, aci_valor_pagamento, bai_fk_pes_codigo, aci_tipo_pagamento, aci_fk_ftm_codigo,…
-
0
votes2
answers621
viewsGroup [group by] SQL Firebird
I wonder if there is a way I can make a query where I can bring fields that are not in my group by. I have the following code: select sum(TAB_FATURAMENTO.vl_item),CLIENTE.insc_cnpj from…
-
0
votes2
answers154
viewsHow to remove Duplicate dates in sql?
Good morning, I need some help for the following problem, I have this code Which gives me the following result, but I’d like to remove the duplicate dates From now on, thank you.…
-
0
votes1
answer678
viewsReceive variable value and insert multiple rows into MYSQL
I have the following variable: $ids = "758,749"; Table has columns: id, id_provider, accepted. When running a PHP script, I would like it to do something like this: INSERT INTO tabela (id,…
-
0
votes2
answers394
viewsHow to bring two columns with different results
I’m looking to put together a vision of the total projects Assets and Closed. I have a table projetos with the fields nome, descricao, ativo (can be S or N) SELECT COUNT(*) as Total FROM projetos…
-
0
votes3
answers2649
viewsSQL to search the entire database
Is there a command to select all tables in a mysql database? Like I have several tables in my database with diverse content. I need a way that a user can search for a keyword in all tables.
-
0
votes2
answers64
viewsDoubt - SQL Server Query
As I do in sql server to get the records larger than 10 days from the current date, that is, in the current month, I want to get all the records prior to day 01-08. I tried that way, but you didn’t…
-
0
votes1
answer1758
viewsQuery parameterized with Node.js and knex.js
In the code below I make a query and bring the contracts that are concluded or not, according to the parameter concluido (0 or 1). How do I bring this consultation all contracts when the parameter…
-
0
votes1
answer75
viewsEquivalent to LEFT() sql function in JPA
What is the LEFT() equivalent function in JPA? I need to take only the first 6 characters of a field. The equivalent select in sql would be: select left(campo,6), count(*) qtd from tabela group by…
-
0
votes1
answer63
viewsFilter dates when user entered our system
I am trying to filter the dates when users connect to my system. Have a however, first need to filter so there are no duplicate users. I’m already doing it using the argument DISTINCT in my query,…
-
0
votes1
answer65
viewsQuery with SQL Server query
I have the following query in SQL Server, to return me a list of cities I need. select IDCidade as "ID", case UF when 'RS' then '1' when 'SC' then '2' when 'PR' then '3' when 'SP' then '4' when 'RJ'…
sql database sql-server query sql-server-2012asked 7 years, 11 months ago Luís Felipe Dal Molin 169 -
0
votes0
answers74
viewsProcedure does not run in codeigniter
function renovarEmprestimos($matricula, $livro){ $this->db = $this->load->database('biblioteca', TRUE); $query = $this->db->query("EXEC J_renovarlivroweb '$matricula', '$livro', '1'…
-
0
votes2
answers74
viewsChecking column fill with CHECK
I am creating the BD of my TCC and the table Clients is: create table clients( id serial primary key, name varchar(255), cpf varchar(11), cnpj varchar(14), .... I thought of doing a CHECK limiting…
-
0
votes2
answers1381
viewsHow to create a Rigger to save updates from two tables?
I have two tables : Tabela1 : three-column id_product, product name, product price; table 2 : four-column id_brand, id_product, tag, price_tag; I created a new Tabela3 : three-column id_product,…
-
0
votes3
answers170
viewsColumns do not hit insertion
You’re making a mistake Column Count doesn’t match value Count at Row 1…
-
0
votes1
answer292
viewsSQL search for more than one type of property, city and neighborhood does not work properly
I got a template ready with some problems in plugins and queries. Of the 6 select fields to do a real estate search, 3 of them can select more than once, property type, city and neighborhood. The…
-
0
votes1
answer243
viewsRenaming values in mysql
I have the following sql query: select nf,status from notas where status = 3 Instead of bringing the number 3 in the result of the sql query, I wanted to show another message: "completed". how do I…
-
0
votes1
answer1652
viewsHow to create a Trigger for a specific column of a table?
I created a Trigger to my table X, with the purpose of making a record of update that run you in this table. For each update on the table X, modified (old) values are stored in the table Z.…
-
0
votes1
answer121
viewsBring record of each ID with the latest change date
I am working with Oracle database and PHP, need to return only one product each with the latest change date, the tables are as follows. product price I have tried several types of query, but I…
-
0
votes1
answer80
viewsRelationship between tables n to n
I’m creating a small project and I’m having a question. Let’s assume that I have a certain types of coffees, these coffees can be served in more than two cup sizes. As the relationship between the…
-
0
votes1
answer97
viewsProblem performing a Java INSERT language
Hello community people, I’m with a problem that I think should be very easy but as I am beginner to me is not rs, I have a Insert to realize that stays in a class called ClienteDAO follows code…
-
0
votes1
answer207
viewsString problem in oracle
I am making a condition to add a field in the database, IE, will only add if the condition is equal to 0. The problem is that in my instruction execute immediate He says the word PRIMARIO is…
-
0
votes0
answers104
viewsFailed to update to registry
I am having the following problem, when I try to change a registry made by my application, it creates a new record instead of changing. My question is, if when I do the trigger of insertion of the…
-
0
votes2
answers87
viewsShow on page total id’s registered in BD
There is a table that shows all BD records, but on a page of my project where I should show the record total(id) of my table. Connection file: <?php $mysqli = new mysqli("localhost",…
-
0
votes0
answers37
viewsQuery with Arrays not working PHP SQL
To edit a report, I need to take everything and turn it into an Array. I cannot use UPDATE, because the user can add more lines, having q add. Thus, I thought of first deleting the data that…
-
0
votes1
answer453
viewsPerformance when comparing Varchar fields in SQL Server
To SQL below is causing much slowness by the fact that I use the Right(L.nrDiscado, Len(D.Descricao)) (believe me) to compare with the field D.Descricao: create table #TempNrDiscado (NrDiscado…
-
0
votes1
answer1383
viewsHow to perform only 1 specific table Restore in SQL Server 2012
Good afternoon! Guys, I have a situation: I have a backup of the database and the server has already been created a database with this base called test, however, I need to migrate a specific table…
-
0
votes1
answer60
viewsselect two tables using Where
I have a table of produtos (id,id_categoria,nome,descricao) and a table of imagens (id, FileName, id_produto). I need to list product data and a product related table image by id. $sql =…
-
0
votes1
answer1334
viewsHow to recover last record inserted in Firebird database?
My Sale table has a Code field with auto-increment and need to recover this code to insert in an associative table. string sql = $"INSERT INTO…
-
0
votes1
answer258
viewsReason for using cursors in databases
I understand what a cursor is, but I don’t understand and I can’t get anyone to show me a real reason to use them. Why should I use cursors? I want answers based on Oracle, SQL Server and Mysql and…
-
0
votes0
answers1736
viewsDifficulty interpreting database diagram
Good evening. I am having some problems interpreting a diagram that from it I will make a sql database. My programming skills are not very good and I would very much appreciate a help. In case I…
-
0
votes1
answer32
viewsHow to select between one hour and another in SQL
I need to solve a simple exercise asking to inform the amount of books sold between 13h and 17h30 of all dates. I was able to pull between 1:00 and 5:00 but not with the minutes "5:30". I did so:…
-
0
votes1
answer80
viewsGrouping of lines Group By
I have the following appointment: SELECT distinct CAPA.COD_HOLDING, CAPA.COD_MATRIZ, CAPA.COD_FILIAL, CAPA.ID_NF_ENTRADA, CAPA.NUM_NF, CAPA.DT_ENTRADA, CAPA.DT_EMISSAO, CAPA.COD_CLIFOR, CAPA.COD_UF,…
-
0
votes1
answer264
viewsDatabase column named with alias not found in WHERE clause
I have this SQL query where I need to name a column twice datareferencia for anobase and mesbase, as follows example. But column error not found is shown. In my view, after I apply the alias the…
-
0
votes1
answer318
viewsHow to update a table by going through another table in Mysql?
I have a scheme according to the picture below: The goal is to update the values of the seller_comission column in the table tbl_history. The table tbl_history already has a few thousand records.…
-
0
votes3
answers928
viewsUpdate in a field that cannot be negative
I need to make a update in a given field, where it should reach at least up to "zero" cannot be negative. And when it reaches zero I need it to give the update of the remaining quantity in the next…
-
0
votes1
answer308
viewsIgnore parameter if null
I have the following method that does a database search: public Collection<Habilidade> pesquisar(HabilidadeForm form) throws Exception { String query = "select u from Habilidade u where u.nome…
-
0
votes2
answers2406
viewsSingle row and column result for multi-row column
I have a function in SQL that returns a single row in a single column with records separated by points. Example: Column 1: Result Line 1: 0000000.0000001.0000002.0000003.0000004.0000005.0000006 I…
-
0
votes2
answers391
viewsError "1241 - Operand should contain 1 column" in Trigger that checks duplicities
I’m doing this Rigger to check if it already exists dados_id and referente_obs in the bank table But returns this error: 1241 - Operand should contain 1 column(s); BEGIN IF (NEW.id_dados and…
-
0
votes1
answer40
viewsError updating given with condition
I’m trying to run this update but it only updates the "value" column if the "discount" column is different from 0.00. If it is 0.00 he enters the second condition of the IF and puts in value the…
-
0
votes2
answers568
viewsQuery creation with Union ALL to join tables with indexing by table name
There’s a problem that they did in a database, which I need to solve temporarily, they created several tables with index in the table name, where the system creates a new table for each new user...…
-
0
votes0
answers81
viewsHow to save my page content to onclick url?
Good morning guys, I would like to know how to save the content of my page in the url with a unique id. Like jsfiddle.net For example, when you first access it has the default url: jsfiddle.net, but…
-
0
votes1
answer405
viewsDELETE in SQL does not run
I’m trying to delete lines from an SQL Express database, but unfortunately I can’t do it. The query is one of those really basic, but after running it I get the message from 'executing query' in SQL…
-
0
votes1
answer156
viewsC# Running a DDL command
I’m trying to run the Ddl command below that creates the table I need, but even not returning error the table is not created, would anyone have any idea where I’m going wrong? public const string…
-
0
votes1
answer844
viewsWhy does this query not work on Oracle?
I am translating a query from SQL Server to Oracle and found an error that makes no sense and I am unable to fix. The error shown is as follows:: ORA-00904: "ITM"."NRO_INT_ITEM": identificador…
-
0
votes0
answers36
viewsConnection error in the Connection string
Hello, trying to connect my VS to Mysql by string connection I get every time error that the server was not found, as I should proceed? private void btnCadastrarConfirmed_Click(object sender,…
-
0
votes0
answers37
viewsFulltextsearch in SQL Server
Hello! All right? I need to make an appointment with fulltextsearch, because it needs to be indexed. However, I am not managing to assemble a query that returns all the possibilities, as if it were…
-
0
votes1
answer46
viewsIf loop registration error
I have a registration form: <form action="Cadastro.php" method="post"> Nome de Usuário: <br> <input class="form-control" type="text" placeholder=" algo parecido com o seu nome"…