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
votes1
answer2284
viewsError 1452 mysql: Cannot add or update a Child Row
I created the following tables and populated in 2 (user and type); CREATE: CREATE TABLE utilizador(utilizador_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,username VARCHAR(100) NOT NULL, password…
-
1
votes3
answers270
viewsSearching data in database
Good evening, I’m having second thoughts about a certain code. It should search all users in the database and list... however of the error... Follow the excerpt of the code where I make the…
-
1
votes1
answer6120
viewsRun script file directly in PLSQL
I have a arquivo.sql, which has thousands of lines of scripts, containing, creations, changes, etc. I need to run this file directly in PLSQL at SQL Window, and nay can be via Command Window. Via…
-
1
votes1
answer1902
viewshow to add different record values?
I’m trying to add the value of id 1 and the value2 of id 2 which in this case would be equal to 220, as I do this consultation? ID VALOR VALOR2 ---------- ---------- ---------- 1 110 100 2 100 110…
-
1
votes2
answers37
viewsUpdate table according to column quantity
The registration table was not modeled correctly, but I need to do an UPDATE by SQL to perform this import, follow example: Note that the children of Bomi Bulsara, need to stay in [nameDoDependent1]…
-
1
votes2
answers112
viewsHow to run a subconsultation on LINQ C#?
How to run a subconsultation on LINQ C#? SELECT ap.ID FROM Aplicativo AP WHERE AP.Tipo IN (2,6) AND AP.ID NOT IN (SELECT filhoID FROM relacoesobjeto WHERE filhoclasse = 555)…
-
1
votes2
answers1212
viewsOnly catch the year of a column in Mysql
I have a query that has a condition, which checks whether the record is greater than or equal to today’s date. He is like that: WHERE t1.bidpack_buy_date => NOW() Well, then he’ll check if the…
-
1
votes0
answers29
viewsNotification of system being duplicated
function Notifier() { switch (Url::getURL(2)) { case 'notifier': $render = 'dashboard/Notifier/notifier'; $model = 'notifier/Notifier'; break; case 'inbox': $render = 'dashboard/Notifier/inbox';…
-
1
votes1
answer105
viewsMount an ALTER TABLE script
I have this select that returns me the name of the tables that interest me: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '%_AUD' AND COLUMN_NAME = 'REVTYPE' GROUP BY…
-
1
votes1
answer222
viewsQuery SQL returns records only after 2 days prior to today
Guys, as I am new to SQL, I need a help. I need to bring only the records that have not been moving for more than two days. The query below is bringing everyone without this condition. I even ran a…
-
1
votes0
answers316
viewsHelp to optimize an index in mysql
I own a site of relationships and for years I try to optimize this query. Almost every day the site hangs because of it. Structure of the user table CREATE TABLE `usuarios` ( `id` bigint(20) NOT…
-
1
votes3
answers1525
viewsHow to create an incremental Update sql command
I have a table Estoque where today there are already numerous rows of records already registered, how can I do an Incremental Update to fill a column that I added the table now? Produto | N_Serie |…
-
1
votes0
answers28
viewsReturn Datalayer value
Good afternoon. I have a precedent that makes some commands and returns 0 = success; 1 = without success; alter PROCEDURE [dbo].TesteRetorno ( @DS_NOME_ARQUIVO_SINCRONISMO AS VARCHAR(200) = null )…
-
1
votes2
answers1079
viewsHow to disable Trigger for all tables in Postgresql?
How to disable Trigger from all my tables in postgresql?
-
1
votes1
answer108
viewsSelect hard with date
I’m unable to do the following:how to return the time in minutes or hours that a certain WORTH occurred in the table below? Example: how long did the WORTH greater than "23" on 01/05/2017? and if…
-
1
votes1
answer127
viewsConstrait Oracle Garden
I have a question, when I create a CONSTRAINT UNIQUE , she measures all the columns together? For example, I want a country not to have names or acronyms equal, in which case I must create…
-
1
votes1
answer270
viewsIs it possible to group a range of values?
I made the following consultation: `select t.net, t.hora, t.`data`, t.`local` from domingos t join( select net, updated, count(*) from domingos where `data` = '07/05/2017' group by updated, net…
-
1
votes2
answers1654
viewsVariable period date SQL Server
Below I have the following code where I search in a table all the data within the specified period in the declared variables. However, a specific client has a different month closure, in this case,…
-
1
votes1
answer97
viewsHelp with Mongodb
I have a problem using the .find() mongoDB with Regexp. I have the following command: db.collection.find({"city": /SAOPAULO/}) When I do: db.collection.find({"city": /SAO/}) it searches on time, but…
-
1
votes1
answer234
viewsHow do I write the following SQL code in the Codeigniter Model?
select count(situacao) as Qtde, sum(valorcausa) as Total_Valor_Causa from processo where situacao = "Tramitando";
-
1
votes3
answers55
viewsI tried a Union consultation but did not get the expected result
I made a query with two selects using union and it has two columns: MOBI and DESMOBI. I need the result to show these two columns. when I run it shows only the column MOBI`. Below follows the query.…
-
1
votes1
answer122
viewsError adding" 0 " to a tinyint(1) field in the database
In my database in the users table, I have a field called status, whose type is tinyint(1). If the status is "0" the user is enabled (can access the site), if the status is "1", disabled. But when…
-
1
votes1
answer85
viewsError making an Insert in sql server with c#
I am trying to make an Insert in a table and am getting an error message. Error image: Code: private void etqmanual() { conex.Open(); SqlCommand comando; StringBuilder Query = new StringBuilder();…
-
1
votes1
answer69
viewsDoubt query - SQL Server 2012
Good afternoon! Guys, I don’t know if it’s possible, but I wanted to know how to get a record of a line in another line. I’ll illustrate. In the query below is coming out like this. Projeto…
-
1
votes1
answer86
viewsInclude new table in multiple Mysql databases at once
I don’t know if it would be possible, but we took a system made in PHP/Mysql from which each client has its own database. But we are creating another tool for this system and of course, will have a…
-
1
votes2
answers1525
viewsBrowse previous record - SQL Server 2012
I need to bring only the records where the previous status was 1, but which is currently 0. I have a table called solicitação containing a field called VencimentoPausado, where this field values are…
-
1
votes2
answers788
viewsProblem with CASE WHEN SQL-SERVER
SELECT CASE WHEN VALOR > 0 THEN VALOR ELSE "Não tem" END AS NOMECOLUNA FROM BLABLABLA I am having an error where it is not possible to convert "has not" to int. The point is that I wanted it to…
-
1
votes2
answers1722
viewsSQL query with PHP array
I have an array that will be variable, e.g.: $ref = array('123', '654', '555'). I wanted to make an SQL query to bring the information of these references, something like: SELECT * FROM tabela_itens…
-
1
votes2
answers2225
viewsHow to take the sum of an entire column in SQLSERVER
I need to take the total value of the VOL field (image below), it is already generated by the SUM function. It can be in another query. All periodic tithes are required. ex: total = VOL(7,6890028)…
-
1
votes3
answers789
viewsProblem sorting sql with orderby Date in postgresql
I have the following query that results in the union of the total sum of an account and the installments select sum(total) as total, datavencimento from ( select sum (con_valoraserpago) as total,…
-
1
votes1
answer589
viewsHow to get the results of two tables by consulting one with PDO?
I have the establishment table, unit table and professional table. In the unit table, I have the idestablishment. On the professional table, I have the skill. I need to pull all the professionals'…
-
1
votes2
answers30
viewsadd lines to datagridview
How can I declare @NIF as a string Dim sqlConString As String = "Server=localhost\TESTE;Database=tempTest;User Id=sa;Password=123" Dim conn = New SqlConnection(sqlConString) Try Conn.Open() Dim…
-
1
votes3
answers77
viewsHow do I link three tables?
I have three tables. Note that if I perform an INNER JOIN in the three tables, I would return only product 1 (Router), which is present in the three tables. However, I would need him to return all…
-
1
votes1
answer631
viewsSending an Array by POST with JSON to PHP
Next, I need to send an array by POST with JSON. I have read about JSON.stringify and in my PHP code use json_decode, but in practice I am not able to apply. I will put the code here and change it…
-
1
votes1
answer711
viewsConnect to sql database a postgres database
Scenario: I have the postgres database A, but I need to connect to the database from sql server 2017. How can I do this?
-
1
votes1
answer129
viewsName of a Role with accent in the Identity database
The need to create a Role with emphasis on the table of Roles of Identity in the database: "Technical". My question is whether this can generate further problems, perhaps at the time of checking…
-
1
votes1
answer52
viewsWhat I need is to take the primary key from the Phone table and insert it into the FK of the Client table. How do I?
CREATE TABLE Cliente ( id_Cliente INTEGER PRIMARY KEY IDENTITY(1,1), nome_Cliente VARCHAR(50), fk_ID_Telefone INTEGER ) CREATE TABLE Telefone ( id_Telefone INTEGER PRIMARY KEY IDENTITY(1,1),…
-
1
votes3
answers671
viewsSelect that respects all values in a list
I need to set up a very simple select, but I’m having a hard time. SELECT SEQPRODUTO FROM MRL_PRODUTOEMPRESA WHERE STATUSCOMPRA = 'I' AND NROEMPRESA IN (1,2,3,4,5,6,7,8,9,11,13,14) I need to select…
-
1
votes2
answers1323
viewsBring results equal to 0 as blank value in a query in SQL Server
I have a query below that the records that have nothing is coming with 0. I wish it could come blank. Example: select F.C37 [Pontuação], ISNULL(count(distinct TD.UsuIDCliente),'-') [Qtde_Clientes…
-
1
votes1
answer152
viewsConnect MS SQL in PGADMIN
Hello, good afternoon! I need to know if there is any tool, script or anything else from where I can have the following scenario: I have a MS SQL database but need to manipulate it through pgAdmin…
-
1
votes3
answers241
viewsIdentifying SQL brothers
I built this link as an example of where I want to get http://sqlfiddle.com/#! 9/72f4b5/4 I have the student table. I have the table with the sibling ids My problem is, I need to make a select so…
-
1
votes1
answer132
viewsCreation query using PIVOT in SQL
Dear I need to display the result of this query in columns, each row represents an employee’s point marking on the day, I’m trying to use the pivot, but I’m not getting.…
sqlasked 6 years, 6 months ago Marcilio Eloi 325 -
1
votes1
answer542
viewsHow to popular a postgres table with JSON?
I would like to popular my tables with Json. But I’m not getting it. Does anyone have any solution? Follows JSON: https://gist.github.com/letanure/3012978…
-
1
votes2
answers337
viewsAdd WITH query inside another query - SQL Server
Guys, how to add the query below as a subconsulta. Consultation with WITH: WITH dias AS( SELECT CAST('2017-06-26' AS DATE) AS dia UNION ALL SELECT DATEADD(DAY, 1, d.dia) FROM dias d WHERE d.dia <…
-
1
votes1
answer40
viewsBackup Database - error in SQL Syntax
I am building a button to make a backup of mine dbvia application C#, everything is going well, but at the time of applying the Executenonquery is accusing error of syntax. Follows: Designate Path:…
-
1
votes2
answers2342
views -
1
votes2
answers89
viewsSQL SERVER - Calculus
I have a question to put together a panel of indicators and I’m not getting out of it. I basically have two tables. Table 1: CONTRACTS Fields: Company ID, Contract ID, Product ID, Quantity Table 2:…
-
1
votes1
answer5598
viewsMultiply two columns in a select
I have two columns (valor_unitario and quantidade) wanted to make a select that multiplied all columns in the field valor_unitario * quantidade. Example: Valor_Unit|Quantidade 15 * 2 + 10 * 1…
-
1
votes2
answers855
viewsUpdate Inner Join (update in two tables) - Php; Mysql
I have two tables and I want to do a Join to update both at the same time. Table1: Clipping (id, dia_semana, data) Table2: imagemClipping( id, id_clipping, titulo, dia_semana, data, imagem)…
-
1
votes1
answer1082
viewsCheck items registered in the checkedlistbox
I am programming in C# in Visual Studio 2015, and I have a form with a checkedListBox with names of several courses (The registration is a student). When marking and saving, it saves the student’s…