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
-
7
votes2
answers1132
viewsSelect too slow, how to improve?
I have a chart of artisans with about 90,000 records. I created the SQL below to return me the total of artisans in each of the regions that they are registered. Although it works, it is slow,…
-
7
votes1
answer4174
viewsHow to concatenate lines?
How to concatenate all the results of a query in SQL Server in order to return all information in one variable? For example, considering a table cliente with the following composition:…
-
7
votes1
answer489
viewsCompare COUNT from two tables
I have two tables and I must return the total of the table with more data, I am doing so: SELECT CASE WHEN ((select count(*) as `familiar` from tb.familiar)) > ((select count(*) as `personal`…
-
7
votes3
answers12428
viewsWhat’s the difference between Cast and Convert?
In a Transact-SQL (Ramalho Series) book it is said: CAST AND CONVERT It implicitly converts one expression of data types to another. CAST is synonymous with CONVERT. What do you mean by CAST is…
-
7
votes2
answers2995
viewsHow the Parallel hint works
One of the first things I see a crowd suggest to boost the performance of a query in the Oracle is the use of hint Parallel. What benefits/risks the use of this hint can bring, I may have problems…
-
7
votes2
answers798
viewsMariadb ERROR: ERROR 1709 (HY000): Index column size Too large. The Maximum column size is 767 bytes
When I run this code on Mariadb, it gives me this error when trying to create the toy table: ERROR 1709 (HY000): Index column size Too large. The Maximum column size is 767 bytes. I don’t know how…
-
7
votes1
answer121
viewsIs it possible to change more than one record at a time?
That is the code: UPDATE PESSOAS SET COR = ('Pardo') WHERE ID = 1; But I have 2 more records to do the same procedure, I could do everything at once adding the ID?…
-
7
votes2
answers441
viewsQuery that returns if the child has inherited the parent’s and/or mother’s surname
I have a scenario that I need to sort my records where: The child inherited the surname of the father and/or his mother? Note in the image that if one of the child’s surnames exists in the parent’s…
-
7
votes2
answers223
viewsIn SQL queries should I follow the order of the index?
If in my table X an index is created with the fields A, B and C (in this order), in the SQL queries I must follow exactly this order? Example following the order of the index: SELECT * FROM X WHERE…
-
7
votes2
answers4291
viewsDifference between date and datetime
I was researching the type of data SQL SERVER and I came across this table What would be the real difference between date and datetime data? Time, minute, second notation only ? What would that…
-
7
votes3
answers3104
viewsWhy does GROUP BY not work with Mysql in this case?
I am using the Mysql language and am trying to group a table of professions with the GROUP BY through the consultation below. SELECT name, occupation FROM OCCUPATIONS GROUP BY occupation; But I get…
-
7
votes1
answer99
viewsDouble rule in LIMIT
I have a news table with the fields titulo, conteudo and destaque, being the highlight int(1), is a boolean value just to check whether a news is featured or not, what I would like to do is select a…
-
7
votes4
answers4763
viewsDelete multiple rows from a database
I’d like to delete several figures. For example this would be to delete a line delete from paginasimagens where idPaginasImagens=121; my values are sequentially so a method that is between elements…
-
7
votes2
answers1093
viewsReplace empty or blank letter, something like Replace("letters","")
There is a field in the database A1_ZTEL he is varchar(15). This way each user entered record of all forms, with bar, point, comma and letter. Now I need to ride a form and read this field from…
-
7
votes1
answer3919
viewsHow to list every day between two dates for more than one record (Oracle)
I applied an orientation of another topic and it worked cool when you only have one record in the table with the interval, but I had problems when the same record has more than one date range. Using…
-
7
votes1
answer151
viewsWhat are index hints?
I saw a comment from @Ricardopunctual that mentioned Density-based index hints your question seems very confusing. it starts with a very basic thing such as "how do I process in sql server", which…
-
6
votes1
answer7768
viewsWhen to use a Unique constraints vs unique indices on Oracle?
Is there any kind of good practice and/or recommendation when creating unique vs indices constraints on the Oracle? When I should wear one and when I should wear the other? Is there a situation…
-
6
votes1
answer1212
viewsIs it possible to create a Rigger that invokes a web service?
I am working on the integration of two databases. It is a system that needs the status of employees in HR. For performance reasons, I can not point out all queries that depend on employees for the…
-
6
votes1
answer401
viewsIs it possible to use timestamp without having to convert to String on Oracle?
I have a query that one of your filters is a date, it is possible to filter in Oracle with something like below? SELECT * FROM tabela WHERE campoData = '2014-02-10 15:56:00.000' Or we always have to…
-
6
votes7
answers2949
viewsHow to use multiple SQL commands (in the case delete on ORACLE) in one line only on C#?
I made a command because of Foreign Keys, only to plug hole, but it is not working for an invalid character error, I believe it is the ";". I know I’m doing this the wrong way, so I accept…
-
6
votes2
answers652
viewsI cannot place a subquery inside the IN in the PIVOT
Below is the code for table creation and insertion of some data for test. CREATE TABLE [dbo].[tb_empresas]( [data] [date] NULL, [nome] [varchar](100) NULL, [valor] [decimal](18, 2) NULL ) ON…
-
6
votes3
answers4703
viewsHow do a select pick up 8 lines in a row or more where there are common values?
I have a table coordenada that has the columns codigo, latitude, longitude, data and would like to give a select which selected only if it had 8 lines in a row or more where latitude and longitude…
-
6
votes1
answer5097
viewsHow to group by month with SQL?
I have a table, for example, with an attribute nome and data (for example only). I would like to generate a query that returns the amount of each row grouped by name and month: Nome Janeiro Fev…
-
6
votes1
answer3804
viewsHow to select categories and count the number of products in each category?
I am trying to select the categories of the database and count in the same query the number of products registered in that category. So far so good, the problem is that I can not return to the…
-
6
votes1
answer1248
viewsSQL Query count
I need to make a query in which the result is the medals (gold, silver, bronze and total (sum of 3)) obtained by each country in all editions of the Olympic Games. So far so good, the query below…
-
6
votes1
answer1827
viewsHow to know which SQL is generated by the ORM Entity Framework?
With the use of ORM, and the practice employed we forget that they generate SQLs and return Objetos (vice versa). How can I find out at runtime the SQL generated by Entity Framework right in the…
sql entity-framework entity-framework-6 lambda-expressions linq-to-entitiesasked 10 years, 7 months ago user6026 -
6
votes3
answers25254
viewsSubtract date and display in YEARS, MONTHS and DAYS
SGBD: Mysql Problem: How to replace the current date with a specific date and return the value in YEARS, MONTHS and DAYS in a query? Example: DADOS DataAdmissao dataAtual 2010-04-07 2014-06-27 (este…
-
6
votes1
answer999
viewsClient installation of SQL Server
I developed an application in C#, which uses SQL Server Express 2012. No development everything went well with access to the database because it is all on the same machine ( utilizo o localhost).…
-
6
votes2
answers2655
viewsDependencies in the same table
A funeral home asked me to do a simple customer registration scheme for them. A client may have several dependents who benefit from their contracted plan if they die. I am in doubt about the data…
-
6
votes1
answer616
viewsQuery to join one column from another
I have tried unsuccessfully to get a result. I have the table with the following login and logout information: |Group |User |EventDate |Event |Camp ------------------------ |Evolution |1012…
-
6
votes4
answers817
viewsSQL Condition Array - PHP
good afternoon, I am sending a search filter to my BD, and I want to make these conditions within an array, for example: $condicoes = array(); $nome = $_GET['nome']; if (!empty($nome)) { $condicoes…
-
6
votes2
answers640
viewsHow to print the SQL statement that is being sent to the database?
I would like to know how to printout an SQL for the purpose of controlling the statement being sent to the database: $sql = $pdo->query("SELECT * FROM imovel WEHRE CATEGORIA = 'APARTAMENTO'");…
-
6
votes1
answer2137
viewsHow to optimize this query query with other sub-consultations?
I have a query query that is taking too long to run (almost 2min) and need to optimize it: select Cidade.Id as CidadeId, Cidade.Nome as CidadeNome, Cargo.Descricao as CargoDescricao, '{0}' as Grupo,…
-
6
votes2
answers441
viewsHow to make a "rbind" in tables of an SQL base from R?
I would like to "merge" two tables of a Sqlite "database" from the R -- and save it to a new table within the same database. Below, I send a minimum reproducible code:…
-
6
votes1
answer4622
viewsSQL increasing ID by 1000 units
I have a database in SQL Express with a reasonable amount of data for over a year. Everything always worked well, but now is presenting the following problem: certain times the ID in some tables…
-
6
votes2
answers1238
viewsWhat is a "0" field in the SQL SELECT?
I didn’t understand the use of 0 in this code: SELECT substring ... 0 AS PARCELADO, ... FROM ... What does he do?
-
6
votes3
answers3470
viewsGROUP BY last entry
I’m making an appointment at the bank, follow my table below id | protocolo | status | alteracao | datahora 1 2 1 teste 2014-11-10 15:23:44 2 2 3 teste 2014-11-10 14:23:44 3 2 4 teste 2014-11-10…
-
6
votes4
answers53244
viewsDifferent ways to count record numbers in Mysql
There’s a difference in performance if you do: //seleciona todos os itens da tabela $cmd = "SELECT * FROM produtos"; $produtos = mysql_query($cmd); //conta o total de itens $total =…
-
6
votes1
answer187
viewsI cannot display the SQL value
I am trying to start a connection to the Mysql database and it works, but when I ask PHP to display what is there nothing appears. It’s like the connection to the BD had failed. <?php //…
-
6
votes1
answer3098
viewsHow to customize Auto_increment numbering in Mysql?
I have a column Contrato in my Mysql database, it is like Auto_Increment, by numbering the contracts as 1, 2, 3... But I needed, if possible, to organize these numbers in the actual format of…
-
6
votes2
answers19743
viewsWarning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in
I’m having a simple problem when it comes time to take a dice from a table.. The mistake is Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in Code: $sql =…
-
6
votes1
answer474
viewsHow to make a query that returns data from the last 7 days without considering Sunday
I need some condition in SQL SERVER return the result of the list of elements taking into account the last 7 days of creation of the same. But he cannot consider Sunday as a valid day in the…
-
6
votes1
answer268
viewsWhat size of a large sizeable query?
What size of a query considerable great? For, I need to make a function to send query for the server but I cannot exceed the limit not to crash the server: public function sqlExecute($sql_code) { if…
-
6
votes1
answer3105
viewsselect with limit in Firebird
I do in mysql to fetch the 1000 last regions: select * from tabela order by id desc limit 1000; Now, how do you do it in the Firebird? doing so have the following error message: Dynamic SQL Error…
-
6
votes3
answers766
views -
6
votes1
answer1481
viewsShould I limit the size of VARCHAR columns for performance?
Normally the maximum size for VARCHAR is 255. If I create the column with a smaller size, say VARCHAR(50), I will gain performance or save disk space?
-
6
votes3
answers71632
viewsHow to make a select in the bank not to bring repeated values?
For example have in the table the values: green, red, blue, blue, pink, pink, pink, yellow. I would need to return from the colors table only once the blue and the pink. Is there any way to do this?…
-
6
votes3
answers2583
viewsSQL of tables with multiple relationships
How would be the SQL representations of creation and correct insertion of the tables below so that it is possible to have/store the total number of videos of a genre so that it is possible to take,…
-
6
votes5
answers10525
viewsShow every day between two dates
I need to display all dates that exist between two set dates. I do not need the information of the difference between these dates, nor the data that are in the interval between them, but show the…
-
6
votes2
answers1087
viewsA Mysql query, with`crases` vs without
With aces to query is safer or less? $Query = "Select * from `tabela` WHERE `id` = `1`"; vs $Query = "Select * from tabela WHERE id = 1";