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
-
2
votes1
answer258
viewsSet the field return size
I have an sql: Select a.nome From tabela a I want to return the name, but imagine my name field is size Varchar(100), but I want to return the first 50 characters. Edit: It’s for IBM’s Informix…
-
2
votes4
answers504
viewsFilter numbers not yet registered via SQL
I’m trying to find the numbers that haven’t been entered in the bank yet. I have a client table, in it I have the fields codigo and nome. When the user registers the client, he puts the code…
-
2
votes2
answers91
views -
2
votes1
answer589
viewsHow to upload PHP data from a Form with text and image support?
In my project I have on a page a form for data collection that will be inserted in the database and in a folder of the server. My problem is that in this form I have a support for uploading images.…
-
2
votes1
answer248
views"create temp table" in Rigger in Postgresql
It is possible to create an Insert Trigger in a "Table1" using "CREATE TEMP TABLE" in its structure and feed a "Table2"?
-
2
votes2
answers1047
viewsError while running project in Visual Studio
When I run a project in Visual Studio it shows the following error: A first chance Exception of type 'System.Data.Sqlclient.Sqlexception' occurred in System.Data.dll Code using System; using…
-
2
votes2
answers2828
viewsCURSOR vs table variable type
I’m facing one of those situations where I need to perform an action for each line resulting from a query. This way I have two options, use a Cursor or a Table Variable, but the two seem very…
-
2
votes2
answers1487
viewsHow to round age with Postgresql?
I used the function age(), below, to calculate age, from a date stored in a table: select pessoa.*, age(data_nascimento) from pessoa; Returned the range: 27 years 9 months 9 days It is possible to…
-
2
votes3
answers183
viewsReturn the difference between the last two records
What I need to do is in this image. How I do? This is the query I did and it’s coming empty and I don’t know why. SELECT event_type, value from teste t1 Where exists (select event_type, value from…
-
2
votes3
answers164
viewsReturn the id of a table in another table
I have a client table containing ID_CLIENTE, NOME_CLIENTE and another approval table containing CLIENTE_APROVADO. The approval table is filled with SOME clients in the client table but only the…
-
2
votes0
answers297
viewsEstados Duplicados
How can I exclude all duplicate Magento states? This occurred due to change of checkout used.
-
2
votes1
answer89
viewsUpdate of multiple Images
My code is currently doing its role well by uploading and putting the watermark on the upload images, however I would like to be storing the names of all images in the database. $idnoticia =…
-
2
votes1
answer81
viewsUpdating hierarchical data using hierarchyId
Hello. I have the following table in SQL Server 2008 The goal is to update the Value field on a child and accumulate in the parent. For example: If in the id record 12 I put the value 31 in the…
-
2
votes1
answer397
viewsError connecting to SQL Server 2012 database - using IIS 7.5 server
I’m getting this Error. Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is…
-
2
votes2
answers810
viewsWhich jQuery event to use for database query?
jQuery(function($){ // Chamando as funções $('#busca-cidades').keyup(function(){ ... I am making a query in the database and returning this query formatted with html/css and the query is in…
-
2
votes2
answers90
viewsReturn columns that accept Boolean in a table
I need a query that brings the name of the columns in a table that accept boolean. Ex: In the table clientes, have the fields casapropria (1 for yes, 0 for no), temfilhos (1 for yes, 0 for no).…
-
2
votes1
answer101
viewsTransferring and summing values from an SQL column
I have two columns in a table, I need the values in column 1 to be transferred and added to the values in column 2. This can be done with a PHP or is there some easier way to do it? Original: ID / 1…
-
2
votes2
answers379
viewsError group by Oracle
When I try to make this group by in oracle it returns me message saying that this is not a group by expression SELECT produto.cd_produto, produto.ds_produto, est_pro.cd_estoque, estoque.ds_estoque,…
-
2
votes1
answer165
viewsTime calculation logged in to SQL
I have a system where user logs in and drops the tool several times a day during their work hours. I need to calculate the amount of time it was logged in: The columns LOGOUT and LOGIN are in…
-
2
votes1
answer111
viewsHow to make this sql
I have the following table: I use a command SELECT, guy: SELECT estudante, conceito_1, conceito_2 FROM estudante WHERE etapa = '1ª' How could I make a single select to catch the 2nd and 3rd steps…
-
2
votes1
answer172
viewsSearch by dates
I have a screen and on this screen I have a Textfield that is filled by a date in the format dd/mm/yyyy and then I convert that date to yyyy-mm-dd which is the format of java.sql.date so far quiet,…
-
2
votes2
answers29844
viewsConvert date to dd/MM/yyyy ORACLE
How to format sysdate for dd/MM/yyyy on Oracle 11g?
-
2
votes3
answers1053
viewsHow to update with SQL Server count?
I have the following table: Nome | Posicao Item1 | NULL Item2 | NULL Item3 | NULL I’d like her to be like this: Nome | Posicao Item1 | 1 Item2 | 2 Item3 | 3 The ordering criterion is Name…
-
2
votes1
answer267
viewsGet data from a column in the database for a variable
In one part of my code I have the treatment of an exception that uses this message. //Grava log com sucesso da importação fundo.registerLog(Resources.MensagemSucessoImportacao); The message is…
-
2
votes1
answer759
viewsUpdate by changing one value by the other in the table
Which update would use to change one value by the other in a table. A update on the table produtos spine cod_produto. I would like a query where in the call table produtos all contained in the…
-
2
votes3
answers92
viewsError in sql server
No sql como faço para fazer um select com espaço e sem espaços? That is, when I have a pass of the genus '123456' and '123456', the last one with space happens to be done in the query and I have…
-
2
votes3
answers7358
viewsHow to avoid calculation error in SQL Server?
I have an appointment that makes a calculation, plus the field "a. totalcustoproducts" appears with zero value in a few moments, then generates a division error by zero, is it possible to pass some…
-
2
votes1
answer380
viewsHow to bring null query Sql server value
I have an sql query where brings the total of a value inserted in a date, but I want to demonstrate in the result the dates that generated zero, even not containing information in the database,…
-
2
votes2
answers3466
viewsSelect all references to a given table (Foreign key)
I need a way to select all the Foreign key of a particular pk. In other words, I want to catch a determined Primary key and select all the Foreign Keys that "point" to her. Preferably I want to get…
-
2
votes1
answer31
viewsHow to concatenate strings with values from a database?
I want to concatenate values from different records, for example, I have the table below: | id | value | | 1 | valor1 | | 2 | valor2 | | 3 | Valor3 | To show the following result: value1, value2,…
-
2
votes1
answer655
viewsScript for Run in Function
I’m performing a conversion on some comic objects where they are with a fixed name of the database. Example: select * from banco.dbo.tabela ... In this case, we are changing this banco fixed, by a…
-
2
votes1
answer604
viewsSql - postgres - Arbitrary accuracy ::
How arbitrary precision works when defining the column as numeric?
-
2
votes2
answers1223
viewsHow to get all data from one table based on another table?
I have a countries table and another table with continents that has as FK the id of the countries table and I needed to return all countries of Europe. Can anyone give a help on how to do this?…
-
2
votes1
answer67
viewsMaximum and minimum payment
I have two tables, customers and payments, I want to verify from each customer which was the largest and smallest payment each made. I did this SQL, but it didn’t work, someone could help me? SELECT…
-
2
votes2
answers757
viewsNULL value in database x performance
I always used database (Mysql) for small projects and never cared about the option "NULL when empty", IE, was blank even. Now I’m designing a big system, I’d like to know the concept of using value…
-
2
votes2
answers365
viewsORDER BY COM GROUP BY to get last Row, sql
I am using this SQL code to retrieve data, first it groups then organizes by birth date of Rows. SELECT U.id, U.born_data, U.bold FROM users U GROUP BY U.bold ORDER BY U.born_data DESC However he…
-
2
votes1
answer120
viewsQuestion with Table Update Trigger
I have two tables, questions and answers, and would like to update the same according to what is selected: Sql Server Database 2005 Problem: --usuário excluindo a pergunta (não está gravando a data…
-
2
votes3
answers1036
viewsGrab last key from auto increment PDO
I have a problem with my system that is the following, try { $sql = "SELECT Nid+1 AS Nid FROM noticias ORDER BY Nid DESC LIMIT 1"; $stmt = $DB->prepare($sql); $stmt->bindValue(":Nid",…
-
2
votes3
answers337
viewsRecover MAX value from an SQL column
string var = ""; SqlConnection con = new SqlConnection(Banco._strCon); string sql = "select max(end_id) from endereco"; SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader dr =…
-
2
votes1
answer7623
viewsGet only first word within a sql server query
Good afternoon to you I have the following query SELECT COUNT (SolID) as quant, UsuNome as gerador FROM Solicitacao INNER JOIN Usuario ON Solicitacao.UsuIDAtendenteViaFone = Usuario.UsuID WHERE…
-
2
votes1
answer667
viewsAnti SQL Injection (I tried everything but Havij still picks up)
Hello! I’m going through a rough patch, I’ve tried ALL the techniques I found on the Internet that can stop SQL Injection, and yet Havij can get my data. This is the code of the page I’m making the…
-
2
votes2
answers2126
viewshow to select only 1 record of each id
After making an Inner Join between user (1) and image (N) tables, the following table is returned (the id refers to the user id and the filename to the image file): | id | filename | 12 | img1.png |…
-
2
votes1
answer758
viewsWrite to a label when it loads with the form
Well, I have a program that needs me to write using Abels, however these only work, and actually write when they are clicked, I would like someone to explain to me how I should proceed to be able to…
-
2
votes2
answers2556
viewsPick start and end date of one week of the month
Good afternoon, you guys. Today I’m having a problem getting the start date and end of a week of the month. Let’s go by parts: I have a combo that brings me the weeks of a month posted. To know how…
-
2
votes1
answer381
viewsHow do I save the value to decimals before the point in sql server?
I have a field in the bank with this format TESTE numeric(8, 3) I want to record this form. UPDATE TB_PLANO_CONTAS SET TESTE = 001.000 WHERE IDPLANOCONTAS = 63 The result is getting like this: 1,000…
-
2
votes3
answers175
viewsCounting filtered dates per day in Mysql
I’m a beginner in Mysql and registered a table on Phpmyadmin, where the id is int, and all other fields are text, including a field data_cadastro. I was in doubt, because there were several types of…
-
2
votes1
answer1201
viewsI must not show negative results
I created a query where I bring some information, among this information the last column returns positive, negative and zeroed values. I don’t want you to display the lines with negative values, but…
-
2
votes1
answer53
viewsSQL Server joining tables with null
I have the following tables: Responsavel | Filho Id Nome | Id Nome ResponsavelId 1 Ana | 1 Aninha 1 2 Maria | 2 Ana Júlia 1 3 Pedro | 3 Mariazinha 2 I’d like to make a SELECT with INNER JOIN where…
-
2
votes1
answer1600
viewsConcatenate columns and some with NULL value
I’m making a select and concatenating the columns, when a column has value NULL (has no value ) the whole line is NULL follows an example: select…
-
2
votes1
answer406
viewsError starting Powershell on Windows Server 2008 R2. How to resolve?
I have installed SQL Server 2014. When starting Powershell in Windows Server 2008 R2 and I do the command "sqlps" to test, happens this error that shows in the image below... NOTE: On another…