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
votes0
answers399
viewsAlter table in giant table
I need to perform an alter table operation on several fields of a table and this table has more than one billion rows. One operation for each field takes approximately 2 hours and now imagines for…
-
1
votes2
answers576
viewsProblem when performing Join in tables with generalization
I’m having difficulty performing a JOIN in tables the problem is the following: In a school bulletin system I have users, including students, guardians and school employees. I need to generate an…
-
1
votes1
answer2487
viewsSyntax error: Missing semicolon
Syntax error message: Missing semicolon is appearing in my END IF, more specifically only the IF is underlined with red: DELIMITER $ CREATE PROCEDURE cadastraEleitor(IN nome VARCHAR(100),dataNasc…
-
1
votes3
answers4839
viewsSQL script to create mask
I’m with a client database that with some data without mask for use in my system that is the field NCM; The same has 8 digits ( ex.: 0000.00.00), However the same in my system this maskless…
-
1
votes1
answer996
viewsGROUP BY - Display grouped result using WHERE as a condition in the same table - Mysql
I am trying to assemble a query to search results in a table where I need to determine a condition for one column, group by another and Display a third. The database consists of 6 Tables, 5 of which…
-
1
votes3
answers1195
viewsConvert nvarchar(50) field to SQLSRV table datetime
I need to change a field in the SQL database table whose format is in nvarchar(50) and data were saved in date format 07/09/2017, containing values NULL also! I need to convert this field directly…
-
1
votes3
answers75
viewsDoubt with registration grouping
In my example, I have a query that return 3 products and the same were purchased in different orders but I do not need this order number. So I did it this way: SELECT c.prod_pk_id, '61068276007702'…
-
1
votes0
answers210
viewsHow to filter active client list in a given period
Good morning everyone. I am developing a management software for a home care company. I have a list of clients who may be active or inactive within a month. Each customer has a contract value with…
-
1
votes2
answers1980
viewsGenerate Inserts from a populated table
I have a populated table and I need to generate the scripts of insert of the data stored in it, I cannot export, it has to be the script of insert into ... Do for select concatenating is very…
-
1
votes1
answer129
viewsDatabase insertion problem - SQL
Follows the code: Update command works: int noOfRowUpdated = ctx.Database.ExecuteSqlCommand("Update Mapa set Geo = geography::Point(47.65100, -122.34900, 4326) where Id= 1"); What does not work is…
-
1
votes1
answer1533
viewsSplit column into multiple rows (split)
I have a table cidade_bairro with several cities and neighborhoods. I want to transfer this data to a new table, but in several lines instead of being in one. EX: Cidade Bairros<br> SP |…
-
1
votes1
answer621
viewsHow to pass Delphi qry.filter parameters
I need to filter data from a grid, but I need to pass by parameter. in case all data needs to be returned. Always do as follows to show all data in Grid Example: SELECT FROM TABELA A WHERE (A.NUM =…
-
1
votes1
answer94
viewsSYNTAX ERROR WHERE - PHP
I have the following code in php: $sql = "SELECT * FROM musicas_curtidas GROUP BY musica ORDER BY count(musica) WHERE musica != 'Rádio Turn - Você em primeiro lugar!' AND WHERE musica != 'Radio Turn…
-
1
votes1
answer208
viewsHibernate error while running web project
I have an error that I could not solve, I start my project and it runs straight. When I access the project via the web, I log in and it. When I click on any button, it gives this error below:…
-
1
votes2
answers952
viewsSql command does not run via php
I’m having a problem with my bd query. I want to make a login page with the following form: <form method="post" action="Login.php"> Email:<br> <input class="form-control"…
-
1
votes1
answer1339
viewsPostgresql - Inserting data into linked tables by Foreign Key
Hello! I’m having a problem inserting data into tables linked by a foreign key. I read in some places that there is a command "with" that helps in these situations, but I didn’t understand how to…
-
1
votes1
answer287
viewsPass a php array in a query and return multiple results
I want to pass a dynamic POST array of type: array(2) { [0]=> string(1) "1" [1]=> string(1) "3" } For an SQL query where it returns multiple results depending on the string values in the array…
-
1
votes1
answer36
viewsApp UWP connects SQL Server 2012 without Webservice?
I need to develop a UWP application in C#/XAML for use in the industry for data collection via Lumia 640 XL cell phone with Windows 10 Mobile. All persistence (CRUD) will be in SQL Server 2012 in…
-
1
votes2
answers554
viewsUpdate and Insert data into a table with information from another bank
I have the following situation: Bench To and the bank B both with the table customers with the following data: A.clientes B.clientes id | nome id | nome ------------------- ------------------- 1 |…
-
1
votes1
answer111
viewsCalculate sql table in android
I have the following sqlite database and works well: db=openOrCreateDatabase("BaseDadosDB", Context.MODE_PRIVATE, null); db.execSQL("CREATE TABLE IF NOT EXISTS tabeladados(data date,total…
-
1
votes1
answer340
viewsHow to search for a string that varies from position
See below two results returned from a table where I store sqls query execution plan. I use POSTGRESQL I need to capture only the string cost=399301.55 of the result below. The word cost always comes…
-
1
votes2
answers13323
viewsHow to add foreign key with Constraint and alter table in Oracle?
I have the following tables : Create table OS( nro_os number(4), data_os date , hora_os number(4) ); Create table cliente( cod_cliente number(4), nome_cliente varchar(12), endereco_cliente…
-
1
votes1
answer252
viewsLeft Join with coalesce
I have the following tables setores(idsetor,sigla,ativo) and another with the services executed called ordem_servico(id,numero,idsetor,). I want to count how many services certain sector canceled…
-
1
votes0
answers443
viewsSQL Server Error When Converting Varchar to Integer Type
FOLLOWS THE ERROR Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the varchar value '280-64460-2' to data type int. SQL DONE USE TOXICOLOGICO SELECT NomeUnidadeColeta,…
-
1
votes1
answer793
viewsReturn Oracle Timestamp
I want to convert a date to a number, a timestamp. Within a select I need to return beyond the date her timestamp. Example of consultation: Select sysdate, TIMESTAMP_DE_SYSDATE from dual Timestamp…
-
1
votes2
answers1393
viewsReturn something in the query when there are no records
I am making adjustments in a graphics system, basically there is a query in the database to bring values and popular the chart, but when there is no specific record does not return anything from the…
-
1
votes1
answer674
viewsImport Sql Server Backup and Differential
I’m having a problem importing a backup to the secondary server: The topology: Server Production >> Server contingency. When Full Backup is imported it matters without any problem. The problem…
-
1
votes2
answers159
viewsQuery mysql problem, what would be the best way to solve
Hello, I am trying to make a query for an order system for a restaurant. My tables are arranged as follows: I need to bring all tables (regardless of whether they have a request or not) if they have…
-
1
votes1
answer87
viewsMake a select according to an indexed table
I have a table, getSalas, that simplified is something like this: CREATE TABLE getSalas( ID_SALA NUMBER(4), NOME_CARATERISTICA VARCHAR2(20), VALOR_CARATERISTICA NUMBER(4) ); The contents of this…
-
1
votes0
answers85
viewsTrigger to format date
create trigger tr_Fmt_Data before insert on Tempos for each row set new.Mes = date_format(new.Datas, "%M"); insert into Tempos (Datas) values("2017-10-03"); Would it be possible for you to help me…
-
1
votes1
answer96
viewsOracle , parameters of procedures of an Owner
On Oracle which table or view of metadata I have the parameters of a Procedure. My question is , that procedures HAS parameters with the name similar to "XPTO" ? I tried for the "Dict" but I…
-
1
votes2
answers120
viewsHow to perform an "IF" by SQL
Hello, how can I do something similar to an if but by sql? For example: There is a field in the database called dt_ini with no value so far. I’d like to do, "If dt_ini == ' ' Insert into table…
-
1
votes1
answer45
viewsHow to migrate Posgresql Script to Mysql Script?
I have this database in Postgresql Script, how to convert to Msyql in order to create this database in this database ? -- -- PostgreSQL database dump -- -- Started on 2010-07-03 09:40:14 SET…
-
1
votes1
answer1643
viewsHow to create Server in Postgresql with port other than 5432?
It is possible to create a server within the Postgresql database with a port other than 5432 ? It is possible to have Server1: Postgresql at port 5432 and Server2: Test at gate 5433 ??…
-
1
votes2
answers168
viewsHow can I see last deleted database database database database
Is it possible to refer to the last deleted file in the database? If yes, how can I do that? The goal is to recreate it.
-
1
votes2
answers225
viewsSelect com group by
I want to group the results that have the same name(varchar) and count the value(int) of the different key_id(varchar). For example, if the records were those: The results would be these…
-
1
votes1
answer24
viewsSums and Reformatting db for a Datagridview
I probably did not draw up a correct title, but I will try to explain my very detailed question. I’m working with Windowsform at Visualbasic15 I need to make a form where I get data from a tb in a…
-
1
votes3
answers634
viewsLike bringing in salesmen who made and didn’t make sales yesterday?
In this select I am bringing all employees who accessed the application yesterday PO.DAT_COLETA and who held blindfold yesterday PE.COD_PEDIDO. But I also want to bring those who accessed yesterday…
-
1
votes1
answer38
viewsList tables to make recommendations to the customer?
I have a table "likes", "commented" and "visited", each time a user likes, comments or visits a particular book on my page a record is inserted in the database for such: Table likes:…
-
1
votes2
answers414
viewsIs there a security problem using the public schema in Postgresql?
First time I’m working with postgresql and I’m wondering if you have a security problem using the public Schema it creates ? Or if it’s just a matter of organization
-
1
votes2
answers1020
viewsDelete record being duplicated in query with Inner Join
I am making a query to my database and in this query I use an INNER JOIN to join two tables! But I have a problem, because I do not know how to manipulate JOIN very well, and this is generating a…
-
1
votes1
answer82
viewsNullreferenceexception when trying to write to database
I have this error, when I will record the form data in the database. Error: System.Nullreferenceexception: System.NullReferenceException ocorrido HResult=0x80004003 Message=Referência de objeto não…
-
1
votes1
answer96
viewsSort records containing numbers at the end
I have a table with the following records: +----+------------+--------------+ | id | title | url | +----+------------+--------------+ | 1 | Olá Mundo! | ola-mundo-1 | | 5 | Olá Mundo! | ola-mundo-3…
-
1
votes2
answers1162
viewsSQL Group same ID with another condition
I believe it’s a little specific question, because I haven’t found anything related yet. I have a table called contas_produtos, which is a relationship Nxn between the tables contas and the table…
-
1
votes1
answer1305
viewsMSSQL How to find out which table a record has been included or modified
There is a way to find out via query which table in a database has changed from Update or Insert?
-
1
votes1
answer112
viewsError when viewing or adding SQL data
Good afternoon guys, I was trying to make an sql to put the score obtained in a game I’m developing, but when I put to save the score, or even see the score it gives error, I will put an asterisk on…
-
1
votes1
answer1651
views"No database Selected" in PHP with Mysql
Columns to receive data: $GravaLinhaBanco = "INSERT INTO `trechosmonitora_cotacao` (`Codigo`, `CodTrecho`, `CodCliente`, `CodLoja`, `Url`, `Rotulo`, `Trecho`, "; $GravaLinhaBanco = $GravaLinhaBanco…
-
1
votes3
answers2562
viewsSum the values of a Count(*) in sql
I’m new in sql and I’m having a hard time making the sum total of the values of a Count, follows below the code: SELECT A.Pais, count(*) from Aeroportos A left join Estacoes E on A.Sigla = E.ICAO…
-
1
votes1
answer55
viewsRead SQL Microft Exported File 2016
I received a file exported from Microsoft SQL 2016 that has extension . txt and the same with . csv and has this face: I searched, but I haven’t found anything yet, someone has some experience…
-
1
votes0
answers353
viewsHow to join 3 queries of quantities of different records?
I need to unite 3 darlings with different results and quantities of records in a single query, using the Where end of script as Where main for all darlings. How can I do this? I tried with the…