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
-
1
votes3
answers369
viewsQuery output on another page
I wonder how I can make the result of a query on a page of mine, fill in a tag on another page; Example: I have a search page the amount of existing processes, when I click the button, let’s assume…
-
1
votes1
answer8462
viewsHow to configure an existing field for auto-increment?
I would like to define the field id already created as auto-increment, because I created the table and did not put this option to it, how could I do this?
-
1
votes1
answer55
viewsWhere increasing condition
I have a table called users and want to catch some users as per id so I’m doing so: select * from usuarios where id=2; Only that I would like to get multiple users with different ids, for example…
-
1
votes1
answer343
viewsSQL - How to count worked days
The ACESSOBROA_NOVO table records the access of company employees whenever they go through a turnstile. I need to do a query in this table that lists the name of the employees and count the days…
-
1
votes0
answers31
viewsProblem with INSERT using quote " "
in my script this working, when put a normal text inserts normal, however when I try to post some code type I am redirected to the error page 403 Forbidden You don’t have permission to access…
-
1
votes2
answers586
viewsApplication does not save data and only saves code
I’m developing software for a video rental company with Pattern MVC design (Model-view-controller) and the problem of not saving people is occurring. It only saves people’s code and I don’t even…
-
1
votes3
answers3400
viewsField value related to another field of another table?
In MS Access I have two tables: tbCursos and tbPeople tbPeople contains: ID, Nome, CursoID, CursoNome; tbCursos contains: ID, Nome; It is possible to make the field CursoNome table tbPeople have the…
-
1
votes4
answers1276
viewsHow to get the amount of records from a Datareader?
I am doing a query in a database, but need to know how many records I will get from this query, before I even start crocheting. Note: I don’t want to put a counter inside the mesh, I need the value…
-
1
votes1
answer464
viewsProcedure to delete and then insert data
Someone could guide me on how to build a database to delete data from a table (already created with SELECT INTO), every day such an hour and then fill it again. Thank you for your attention.
-
1
votes2
answers556
viewsSql server - default
Good evening, I created a table to test the sql server default: I did a select to see if the default values were entered but you can see in the image that this did not occur. When does it enter…
-
1
votes1
answer45
viewsSQL to know the last edited record
I have the following SQL: $dcadastroultimo = date("d.m.y"); $sqlidcidade = "select id, titulo, tipo from imoveis where cod = '$cliente' AND ueditado <= '$dcadastroultimo' ORDER BY id ASC"; I need…
-
1
votes1
answer415
viewsHow to see the disk space that the index occupies in the database?
I have the table maintenance with the column id_product (varchar(MAX)), however the same is not the primary key, the table has 900 thousand records so I decided to create indices to optimize…
-
1
votes1
answer200
viewsBring value from a grouped record
Dear colleagues I took a query that I thought was simple but it’s complicated! I have a database where I have all my NF per commodity input product, I need to find the product value in the last…
-
1
votes1
answer45
viewsQuery result with SET STATISTICS
I was wondering if there’s any way I could get the results of "SET STATISTICS TIME ON". For example, the result of my query gave 1139ms. Is there any way I can get this result and manipulate it?…
-
1
votes2
answers12423
viewsOracle Insert of multiple lines
I need to input multiple records into a table where only one of them will change, the others are constant. For example: Insert into processo (ID, status, descricao) values (1, 'X01', 'lorem ipsum…
-
1
votes0
answers162
viewsINNER JOIN returning error
I’m trying an INNER JOIN between 3 more tables returns error, I don’t know what’s wrong. Query: SELECT aa.arq_arqid, aa.arq_nome, aa.arq_nomecrip, aa.arq_datetime, u_usuarios_u_userid…
-
1
votes1
answer225
viewsJava check two tables inside Sqlite
I have a database that has two tables, being them EstoqueDBQ and FilaDBQ, I need to create the following logic. If the value exists in the table Filadbq and in the EstoqueDBQ, this value should be…
-
1
votes1
answer1629
viewsAutomatic database synchronization in Mysql
Good morning, I have a local Mysql database where the availability is 24h, however I have another database in another location that is available for a few hours, anyway... I want to synchronize two…
-
1
votes1
answer376
viewsHow to convert certain group of columns to JSON?
I have the following problem: I have a table with N columns, however, I would like to turn almost all of them into a single json column, e.g.: id, json(col2,col3,col4) as dados I looked at the…
-
1
votes1
answer51
viewsRepeat id query most times
I have two tables, one user and another visitas. On the table visitas i save the ID of the user that was visited and who visited. How to make a query where I leave users in order of more number of…
-
1
votes0
answers116
viewsMysql Query in Node ignoring difference condition
I have had a peculiar problem while changing my Node.JS server to certain Mysql queries. I have the following code that works normally in Mysql Workbench: SELECT id, nome FROM `tabela` WHERE…
-
1
votes1
answer31
viewsHow to use a table in the database with different fields of the model layer?
For example, I have a table where the field in the bank called COD_CLIENTE, but in the model layer it is ID_CLIENTE, how to access this value without changing the name of the in the VB.net? Partial…
-
1
votes2
answers131
viewsHow to use special mysql order_by in codeigniter
in mysql I can do so. SELECT * FROM `Cidade` ORDER BY `id`=1347 DESC But I can’t do it in codeigniter, I’m trying it like this: $this->db->order_by("id = 1347", "DESC") ->get("Cidades"); In…
-
1
votes1
answer324
viewsMake Trigger run update after Procedure has been run
I would like to know how I do in SQL Server for a Trigger check if the trial was executed and if it was executed, this Rigger will do another update. Thanks for your attention. Att, Marcilio…
-
1
votes1
answer5453
viewsCheck if date is between a period
On my table, I have two columns, DT_INICIO and DT_FIM, would be an Absence table. Let’s assume an employee is absent from DT_INICIO From (25/03/2016) until DT_FIM (27/03/2016), I need to make an…
-
1
votes3
answers223
viewsPDO Pagination - Fatal error: Out of memory
I am making a pagination, but it is generating a memory error. Is there any way to optimize or fix the fault? Or is it on the same server? Note: the php.ini this set the memory in 512. if…
-
1
votes1
answer704
viewsOracle SQL - Query multiple schemas
I was able to assemble the result, now missing create the view with this result. Which is the best way? This consultation: "SELECT CONCAT(CONCAT(CONCAT('SELECT * FROM ',a.OWNER),'.TAB2'),CASE WHEN…
-
1
votes1
answer4041
viewsHow to select all tables containing the field with the same name?
I need to search all fields "id_category" in a given database, and bring a list of the tables that contain this field in common, which in this case is the foreign key of the table "sis_category".…
-
1
votes1
answer799
viewsRead data in an SQL with columns of equal names in different tables
I need to recover data from 2 tables. My SQL presented below works perfectly. The problem is that I made a foreach to recover data from the second table by field ID that is conflicting with the…
-
1
votes0
answers182
viewsReceiving API POST
I’m having trouble receiving data via POST from the Cielo API. I’ve already spoken to King Host and everything is right about the certificates and so on. I did some research on Github and found a…
-
1
votes1
answer541
viewsSQL - Codeigniter - Returns only one record
Gentlemen, I have the following function: // Busca Simples public function buscando(){ // pesquisar_palavra, idCategoria, idSubCategoria if($this->input->post('pesquisar_palavra')){…
-
1
votes2
answers4528
viewsIncrement a number in an SQL query
I have the appointment that returns the results. I would like to add an incremental number to show the records from 1 to the end, as if it were a new column. select *, sum(valor) as ValorSoma,…
-
1
votes1
answer408
viewsInsert to foreign SQL keys
I am learning a programming language and I set out to develop a budget program. My first obstacle is to add the values of the primary keys in the foreign keys of the respective tables. This code…
-
1
votes1
answer222
viewsUlitization IS DISTINCT FROM - Postgres
What is the best use of this function in Postgres IS DISTINCT FROM, doing tests obtained the same result using COALESCE but in less time, follows the test: SELECT COUNT(P.id) FROM produto P INNER…
-
1
votes1
answer319
viewsTaking reserved SQL words out of a Java string
I’m making a view that has an open field (textarea) where the user can write SQL and then run the same SQL. The point is that the oracle user where it will run SQL has permissions for everything and…
-
1
votes1
answer71
viewsSQL query returns
I have a table for the query to send the information there, and it appears " " instead of letters with accents. I am already using html <meta charset="UTF-8"> Is there something missing? This…
-
1
votes1
answer48
viewshow to add a value per parameter to a select statement in sql within a simple table-Valued function?
this is my code and wanted to add a value to a select statement that is passed by parameter to a simple table Valued function. Here is my code: CREATE FUNCTION NMELHORESFORNECEDORES(@N INT ) RETURNS…
-
1
votes3
answers328
viewsSQL - Query in a single table with null values
Hello, I need to make a date-filtered query. The problem is that non-existent dates in the table need to be returned by the query, having all other fields as Null. SELECT Data, Servico FROM…
-
1
votes0
answers61
viewsMultiple update commands separated by ";" (dot and comma) in Sqlite!
Problem I am trying to apply the following script/command to a version of my Sqlite database: UPDATE UF SET DATE_CREATE = DATE_UPDATE; UPDATE CIDADE SET DATE_CREATE = DATE_UPDATE; UPDATE CLIENTE SET…
-
1
votes0
answers58
viewsHelp with PHP and SQL Error
Guys, I’m doing a project at a video store, but the data is not being sent, this is the code: <?php $host = "localhost"; $user = "root"; $pass = ""; $banco = "locadora"; $conexao =…
-
1
votes1
answer150
viewsNOT IN SQL ( I want to select pilots who have never done a certain route) how?
I want to select the pilots (in this case commanders or co-pilots) who have never flown the route 12345 . At the moment SQL is returning all pilots and I want to return only the 18200 the 25100 and…
-
1
votes1
answer43
viewsChoose second smallest occurrence on a Rigger
Trigger that prevents a candidate who has stayed in the penultimate place during the last two months to apply for a new job so what I need to do is before entering the data into the table…
-
1
votes3
answers15705
viewsSQL CASE with more than one condition
I would like to know if it is possible to use the CASE more than 1 condition. In this query I have calculations that need to be done when a.operacao == 'C' but which depend on the value of…
-
1
votes0
answers154
viewsQuery using Firebird "SUBSTR" with Inline, QueryOver, Criteria
Guys, I need to create a query using the "SUBSTR" function of Firebird with Line, queryOver or Criteria. I have option to create with HQL or SQL, but these would be my last options. Anyone have an…
-
1
votes1
answer1867
viewsexplode() right on Mysql
I have a column called relacionados on the table produtos and there are some ID’s of some table items produtos. I needed to make a explode() or something like that on the table produtos and selects…
-
1
votes2
answers12794
viewsHow to create a Mysql database with SQL commands?
I would like to know how to create a database in Mysql using SQL commands, which I can run in Mysql Workbench, phpMyAdmin or any other software. What SQL commands are needed to create a database and…
-
1
votes0
answers55
viewsFormat Mysql data
I have a problem when passing a date to a select. Using the form below, select me returns the data normally: SELECT H.* FROM HORARIOS H WHERE NOT EXISTS ( SELECT * FROM RESERVAS R WHERE H.COD…
-
1
votes1
answer404
viewsHow to merge lines?
How can I merge two or more **Linhas x Coluna** of the consultation below? select cast(OS.CreateDate as date) as DtMovimentacao, OS.Id as NrOS, OS.Description Origem, OSI.Description as ItemSaida,…
-
1
votes1
answer50
viewsJava - Class does not display requested information
Good morning, I need to fix a problem when I ask in "dao. Access" the get of the model class.User returns vázio = null. When it is called: doLogin(model.Access access) you see the information by…
-
1
votes4
answers739
viewsIs it possible to put an "IF" condition on media to Internet joins and other Where conditions in SQL Server?
I have a procedure that takes a parameter that can be 0, 1 or 2. When it is 1 or 0, it needs to consider the line where it has "and bol_portfolio = @eh_port", but when it is 2, it cannot enter this…