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
-
4
votes3
answers137
viewsSQL Query - ORA-01795
I need to make a report from a database query. The problem is that the query returns more than 1000 expressions and presents the following error: ORA-01795: the maximum number of expressions in a…
-
4
votes3
answers283
viewsHow to delete duplicates between multiple tables
I have three tables with structure similar to this: CREATE TABLE itens_chao ( id int PRIMARY KEY AUTO_INCREMENT, pos_x int, pos_y int, nome varchar(255), quantidade int, numero_serie int(11) );…
-
4
votes1
answer36
viewsSort distance record based on latitude and longitude - Laravel
I have a table companies who has a one to one polymorphic relationship with addresses I have the parameter of latitude and longitude and I would like to order the Commissaries to the distance of the…
-
3
votes4
answers650
viewsReturn multiple arrays using a buffer without overloading memory
I’m developing an application where, in a report, I need to print something around 50,000 lines. When having run SELECT error occurs: Fatal error: Allowed memory size of 134217728 bytes exhausted…
-
3
votes1
answer416
viewsMark duplicate fields in a table
I have a table in my database and I would like to mark the occurrences where a certain code is repeated. Remembering that this code field is not a primary key. Example: Data Código Repetição Status…
-
3
votes2
answers394
viewsUpdating the multiple database structure in Azure
I have 5 SQL database (Web Edition) in Azure which must be exactly the same as the structure (procedures, tabelas, views, triggers,...) but the data is different. It has to update the structure of…
-
3
votes2
answers3089
viewsHow to filter results and reload the/view page in Codeigniter?
I have a code in Codeigniter that takes a value of a select dropbox in a view and leads to a second view showing the results in a table. In this second view, I kept the dropbox and the button of…
-
3
votes1
answer205
viewsSqlite - count primary keys that were not referenced as foreign key
First, I am trying to count the primary keys of a table that WERE and WERE NOT referenced as a foreign key in another table. Also, I want to filter the search using the clause LIKE to show only…
-
3
votes2
answers1098
viewsUnable to load dbxmss.dll in Delphi XE4
When trying to connect, in Delphi XE4, a Tsqlconection with MSSQL, it asks user and password. After ok, appears: Unable to load dbxmss.dll I already searched the computer and there is this dll, nor…
-
3
votes1
answer1757
viewsTo assign the value of a variable that is in a Javascript function, for an SQL query.
I have a javascript function that gets the value of the selected item in a combobox, and would like to pass this value as parameter to an SQL query to bring the data that is related to the value…
-
3
votes3
answers614
viewsDatabase query in Postgresql
I am trying to make a query in Postgre with the following query: SELECT t3.desc_serv, t3.nm_serv, t1.nm_usu, count(t2.id_atend) TOTAL_ATENDIMENTO FROM usuarios t1 INNER JOIN historico_atendimentos…
-
3
votes3
answers9315
viewsSum results values in mysql
I am servicing a bank and am finding it difficult to make a select. Table structure descontos_taxas: id | value | client | data_created My Scenario: This table holds both rates and discounts in the…
-
3
votes1
answer475
views"Linked Server" with Mysql
DBMS: SQL SERVER 2014 + Mysql 5.5 What are the syntax of SELECT, INSERT and UPDATE instead of using the "OPENQUERY" function, when connecting through the SQL SERVER Linked Server, connecting in…
-
3
votes1
answer750
viewsHow to update field in SQL table without blocking it?
I have a table with many records in production (almost 3 million), and I need to update a field with a very simple query: UPDATE tabela SET enviado = 1 WHERE enviado is null About 2.5 million will…
sqlasked 10 years, 5 months ago Andre Figueiredo 5,030 -
3
votes2
answers835
viewsHow to group dates according to the day of the week
Well, I have a table which has a column of id user’s user_id and one with dates. I would like to know how to group and count the dates that are in the formed. Example: 07.06.14 on the respective…
-
3
votes2
answers1680
viewsHow to make rounding every 5 tenths (0.5)?
I have a select that returns the average of the columns. I used Round to remove a few decimal places and round the numbers. The possible numbers of the fields are integers from 1 to 5, and when…
-
3
votes2
answers327
viewsPHP and Mysqli. Table link problem
I’m following a toturial, it’s all the same. My problem is I can’t connect to the table. connect.php: <?php $db = new mysqli('127.0.0.1', 'user', 'pass', 'app'); if ($db -> connect_errno) {…
-
3
votes1
answer7688
viewsError comparing ORA-00932 dates
I’m having a problem comparing two dates in the oracle. I’m using the case method to compare the dates and at the end this should return to my table a number, which in the case represents an age,…
-
3
votes1
answer987
viewsORA-00911: invalid Character
I’m having trouble with Oracleparameter, I could not find the problem, because I can not see the sql after the assignment of the parameters... follow the code: private DataTable GetSearch() { string…
-
3
votes1
answer4700
viewsUniting several SQL queries in a single query
I have a 'mission' in my work, where I need to unite some queries in a single query. But I have no idea how I can do this so that everything I need is returned using just one query to the bank. Is…
-
3
votes2
answers1273
viewsHow to bring in the SELECT result the conditions entered as parameters?
Is there any way to bring in the result of SELECT the parameter values used in the clause WHERE ? Example: SELECT a.*, cast(:dataIni as date) AS inidate , cast(:dataFin as date) AS inidate FROM…
-
3
votes2
answers379
viewsHow many images can I save to a mysql blob field?
I can record multiple images in one field blob? Or I’ll have to create several fields? Imagem1, Imagem2 etc.... ? I wanted to know if there is any way to do this without having to create several…
-
3
votes1
answer668
viewsHow to change multiple records of an sql table at once?
Imagine a result of an SQL: ID - NOME- MENSAGEM 1 / israel / msg-olamundo 2 / rafael / msg-olamundo 3 / augusto / msg-olamundo Now I want to do in SQL the same thing that str_replace would do in php…
-
3
votes2
answers54
viewsIs it possible to check the fields?
My problem is, "I have one array which stores data from duas combos. In a combo i add "P" and then the entered value. Ex: P111111111. And the next I add at the beginning "S" and it gets S11111111.…
-
3
votes2
answers439
viewsHow to select data from different tables
How to make a select picking a field from each table? I want to get the text field from 4 different tables, as I should?
-
3
votes3
answers800
viewsList every month in an intevalo, or in the query or in the programming?
I’m making a chart that lists a certain amount per month, but can have mès that has nothing, with this returns me no value and does not list in the chart. I don’t know if I should make the change in…
-
3
votes2
answers101
viewsQuery of N records by Item
I have a history table on DB2 and would like to carry out a PLACA however despite this I would have to return the last 5 records of each PLACA. Ex.: |ID |PLACA | DATA | VALOR | |12 |ABC | 2014-08-28…
-
3
votes1
answer5211
viewsSQL Group query with more than one distinct attribute
I have an application that generates approximately 25000 records per day in BD. This will generate a large amount of id’s per day in the user’s BD. According to the user’s business rule, only failed…
-
3
votes1
answer414
viewsMicrosoft SQL Server Error 10060
I recently formatted my computer and reinstalled the applications. Among them SQL Server 2014. The problem is that I can’t connect to the provider’s server! I uninstalled the 2014 version and…
-
3
votes1
answer41
viewsHow to set up a field using three others?
I have the following fields in the database: | id| estados | cidades | categoria | todosjuntos | | 1 | mg | sao paul| informati | mg/saopaulo/informati | The first four are populated, but I would…
-
3
votes1
answer264
viewsRelational model in Firebird with C#
Developing a small C# project with Visual Studio, Firebird bank and ibexpert. With the tables WITHOUT RELATIONSHIP I can perform everything well. But I need to relate CLIENTE 1:N with BONUS And…
-
3
votes1
answer1006
viewsHow to complement this sql query?
I have the following tables below, where schemes(columns) are described in parentheses and the primary key appears in bold: pupil(codpupil, named, dt_ticket, codcurso) course(codcurso, naming)…
-
3
votes2
answers4048
viewsReturn which of the query items are not in the table?
Is there any way to return which query items are not in a table? Let’s say I have an appointment like this: SELECT id FROM tabela WHERE id IN (1,23,45,68,91,126,345,418,509,610); This will bring me…
-
3
votes1
answer321
viewsBest SQL DBMS for with large bases (RAIS > Mem RAM)
I am trying to write a routine to automate the import of RAIS public micro-data and to work with it on a normal computer (RAIS size > RAM) What is the best SQL software (DBMS/protocol) to use?…
-
3
votes1
answer621
viewsI cannot import data from a CSV to Postgresql with dbWriteTable from R
I am trying to import a CSV into a Postgresql database from R. On the Postgresql server, I created an empty database, called "Data". library(RPostgreSQL) library(sqldf) drv <-…
-
3
votes2
answers1246
viewsCount number of records in a database
I want to count the number of records in a database table. I have 3 records in my DB, but the result is always 1. I used this code: $base_hndl = new SQLite3("p.sqlite"); $select = "SELECT COUNT(*)…
-
3
votes2
answers106
viewsObject Variable type and Expressions
I wonder if you have any way to mount an Xpression on ssis that returns true or false on a variable of type Object : basically would be something like in sql 12 in (14,25,45,12,54) but in Expression…
-
3
votes1
answer71
viewsError restricting dates in SQL Server
I get 3 databases that are mounted in different locations, these bases come to me in text file (.txt) and I import to SQL Server. I’m making a query in which I want to restrict the records only for…
-
3
votes1
answer47156
viewsRun oracle Procedure
I created this protocol, but I can’t execute it. I have the following error when trying Execute: PLS-00306: incorrect number of argument types in call to 'SP_CARTAO' CREATE OR REPLACE PROCEDURE…
-
3
votes1
answer1400
viewsSearch registry by date in mysql
Good night, I have records in my table about phases of the moon 4089 Lua nova 1983-05-12 19:26:41 4090 Primeiro Trimestre 1983-05-19 14:18:16 4091 Lua cheia 1983-05-26 18:48:29 4092 Quarto Minguante…
-
3
votes3
answers1579
viewsSelect the two highest values of a tuple
I have an appointment that displays the following result: ID | v1 | v2 | v3 | 54384 | 2.4 | 8 | 2.55 | 54385 | 5.6 | 1 | 3.24 | How to do, in a SELECT, the selection of only the two largest values…
-
3
votes1
answer112
viewsUpdating data in SQL
I have a table with the following fields: Nome(VARCHAR), Email(VARCHAR), Credito(INT) I wanted to know how, or with what command, I do to decrease or enlarge the field Credito. I know you have to…
-
3
votes3
answers1773
viewsHow to bypass an accent in mysql + Php
I have in my database words with accents and when I want to call I use this SQL below. But if a word in the database has accent I need to also use the word accented in my search, otherwise nothing…
-
3
votes1
answer103
viewsConverting an SQL from Sql Server to C#LINQ
I have an sql that looks like this: SELECT coluna1, coluna2, coluna3 FROM ( SELECT coluna1, coluna2, coluna3, ROW_NUMBER() OVER(ORDER BY coluna1, coluna3 desc) as row FROM tabela1 WHERE coluna4 in…
-
3
votes4
answers632
viewsHow to execute two querys in a statement?
I need to mount a Mysql query that returns the total of rows, and the total of lines with value greater than 1 in the same query. Total of lines: SELECT COUNT(*) FROM tabela Total of lines with a…
-
3
votes1
answer144
viewsDisplay subquery result and use it for calculation
I need to present a result of a subquery and use the same result to perform a calculation, is it possible to play it for a variable in MS SQL 2008 or something like that? example: SELECT @test =…
-
3
votes2
answers10071
viewsUpdate to clear entire column
I need to make a update in the database in which zero 30 thousand records, however I need to reset only the record of one of the columns. Example table: cd_product|ds_product|pr_product|dt_update…
-
3
votes1
answer1433
viewsProblems with NOLOCK, READ COMMITTED SNAPSHOT
I always see sqls mounted with WITH NOLOCK that say improve performance, but I’ve also heard that NOLOCK is obsolete and what should be used now is READ COMMITTED SNAPSHOT, in this scenario my…
-
3
votes1
answer88
viewsGet Rows from at least 3 days ago
I have a table with column datetime and I need to get the results that already have 3 days of existence, all more than 3 days, I tried to use SELECT *, DATE_FORMAT(date, '%m/%d/%Y') FROM tb WHERE…
-
3
votes4
answers5376
viewsSELECT within the UPDATE
I have the following database: cd_telefone|cd_cliente |nr_ddd |nr_telefone 1 | 30 | 11 |2562-2791 2 | 30 | 11 |2562-2791 3 | 31 | 13 |8888-8888 4 | 30 | 11 |5555-5555 5 | 30 | 13 |9623-54002 6 | 30…