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
-
5
votes3
answers24766
viewsIs it possible to use if Else in Mysql queries?
I’ve been searching the internet and hearing rumors that it is possible to use if else in Mysql queries but saw nothing concrete about it. Is it even possible? If so, how? I want to make a query in…
-
5
votes2
answers1081
viewsRun SELECT within a CASE
I’m using the php to make a SELECT of the database, but I need the select check that one of the fields has been filled in and, if yes, run a new SELECT from another table. Basically the idea is that…
-
5
votes2
answers1943
viewsUsing AND inside an INNER JOIN can?
I wonder if it is possible to use AND within a INNER JOIN, example: SELECT * FROM tab1 INNER JOIN tab2 ON tab2.id2 = tab1.id1 AND tab2.camp1 = 'valor' INNER JOIN tab3 ON tab3.id3 = tab2.id2; I gave…
-
5
votes2
answers2074
viewsChecking remaining days between current date and contact deadline
Good afternoon everyone, as per the code below, I am not being able to check the remaining days between $data and $prazocontact. $consulta = mysql_query(" SELECT s.id_cliente, p.nome_servicos,…
-
5
votes1
answer776
viewsAllocation Space for Mysql Fields
First I create the model in my application, then the Entity Framework generates the SQL for the table creation. The first statement generates a column with the type varchar(20), the second generates…
-
5
votes1
answer1258
viewscompare and add in sequence with sql server
through a table I intend to add the fields of col3 verifying if the value of col2 is equal to the following, doing a group by sequential. col1 col2 col3 ind seq1 5 ind seq1 3 ind seq1 7 ind seq1 4…
-
5
votes2
answers4615
viewsSQL LIKE is Case Sensitive(Case Sensitive)?
By having this doubt, I did not find quick results in Portuguese that offer answer(most of the results are in Stackoverflow in English). It would be interesting to have an objective answer here in…
-
5
votes3
answers421
viewsQuery with conditions in SQL SERVER
Follow the tables below with my question I have a problem, where I make a filter in which I need to get the posts that have the column post_parent of the post table with value other than 0, and also…
-
5
votes1
answer433
viewsHow to select multiple columns using the table prefix only once?
In relational model condition, I have to specify the prefix of the table, I’m sure? Example: SELECT c.nome, c.idade, a.nome, a.idade FROM... What I wanted to know is if you can’t do something like…
-
5
votes1
answer142
viewsWhat is the difference between the new JOIN operator and the previous ones?
I was looking at some examples of SQL in Oracle, and I noticed that it is possible to do only JOIN. Example SELECT T1.*, T2.desc FROM table1 T1 JOIN table2 T2 ON T2.id = T1.id_table2 Question What…
-
5
votes2
answers14121
viewsSQL query for nonnull records only
I have a table NotasFiscais and I’m searching all the records it contains in the column NChave. But some result contains this information and others do not, in the case are as NULL. How could I…
sqlasked 7 years, 7 months ago Igor Carreiro 1,917 -
5
votes1
answer1602
viewsHow to avoid deletion of relational data through referential integrity in MYSQL?
I have the tables SIMULATED and QUESTAO, where a simulated can have several questions, but a question can only be for a simulated (relationship 1-n). MOCK TABLE: simuladoId simuladoNome TABLE…
-
5
votes2
answers2991
viewsSQL for last month and last two months
Hi. I’d like a hand here. I need to get the records: Mysql bank 1) last month 2) last quarter 3) Current year SELECT id, data, lote, modelo, qtd FROM controle_diario WHERE modelo like ? The table is…
-
5
votes6
answers32941
viewsConvert varchar to date in SQL
You can convert dates into sweep for date. I’m having difficulties in performing searches between dates, due to this discrepancy in the database where I perform the query. When I enter my line of…
-
5
votes1
answer3762
views -
5
votes2
answers354
viewsWhy does max not even min return the expected value?
I need to take the highest and lowest value of a given field to be able to make a filter, only SELECT MAX or MIN does not work. As you can see in the image below, I need this amount of users Table…
-
5
votes1
answer217
viewsBetter BD structure with large number of data and filterable columns
I have a Mysql database with a table that is taking too long to complete a query. I would like to know what would be the best database structure indicated for a table with many fields that are…
-
5
votes2
answers1969
viewsHow to get the Primary key Identity of an inserted record?
I need to create a stored procedure to insert a game into my database. A game relates to a championship through the table campeonatoJogo. The tables are basically: create table jogo( codJogo int…
-
5
votes1
answer358
viewsWhat is the amount of $_POST records of a dynamic input form?
I have a form with dynamic fields but I realized that when sending it limits to 166 records. In my form the fields are inside a WHILE so: <input name="contagem[]" type="hidden" value="<?php…
-
5
votes3
answers1988
viewsHow many days to a date
Does anyone have a query in sql server that returns how many days to a date? I have the employee’s admission date, I need to know, how many days are left to complete 45 days and how many days to…
-
5
votes2
answers10554
viewsSelect with "different" expression with two conditions
I wonder if there’s any way to make a select using a where for a field with the parameter other than < >, where it has two or more items. To facilitate follow example: select * from…
-
5
votes1
answer39
viewsWhat is the best way to insert with SQL?
I say that because there are two ways. Has the: INSERT INTO teste SET nome = "Lucas", sobrenome = "Alves"; And also the way: INSERT INTO teste (nome, sobrenome) VALUES ("Lucas", "Alves"); Speed,…
sqlasked 7 years, 2 months ago Lucas de Carvalho 6,427 -
5
votes1
answer106
viewsCalculation of hours within consultation
I already made this account and it works right in C++. My problem is to do inside a select to appear in the table. If someone wants to see the C++ algorithm to help mount in Mysql I can send. This…
-
5
votes2
answers972
viewsRegular expression with specific ending bring 3 first characters
I am trying to make a regular expression on Oracle with the following requirement: End with a specific letter if you have this letter in the middle not searching. Return the first 3 digits of the…
-
5
votes1
answer525
viewsWhat is the difference between INNER JOIN and INTERSECT?
What is the difference between INNER JOIN and INTERSECT? Someone can also illustrate?
sqlasked 6 years, 12 months ago user75204 -
5
votes2
answers287
viewsMysql query - Cross Tables count
I have the following tables: Each tuple of the table Pageviews (main) contains a single page view. If by chance the same person in the same session (Sessions) view the same page (Pages), a new tuple…
-
5
votes1
answer1341
viewsHow can I list all invalid emails?
I ended up finding something like this due to the lack of validation that we didn’t have. teste@cliente calteste5@calteste5 calteste6@calteste6 vava@ius Pablo Fernandes xxx eduardostubbert 123456…
-
5
votes1
answer461
viewsRescue all nodes from an Sqlite database tree
I have a serialized tree in my database in the table arvore. Like any good tree, every node can have at most a single parent node. Your data is in this format: id | id_pai | valor…
-
5
votes2
answers402
viewsHow to select records in an Auto-referenced table using Recursiveness?
In a scenario of areas where one area can be supervised by another is representing in a tree structure as follows: Problem: The need to select the Área (CBT - Cubatão Industrial Complex) plus all…
-
5
votes2
answers1719
viewsHow to search two words in the same Mysql field
Good morning. I have a field on my table called tags, would like to do a search, where two or three words can be considered. Example: In the field tags, I have some words, like "free", "cabins",…
-
5
votes4
answers13421
viewsQuery INSERT with WHERE condition
How can I make an Insert with a Where condition? I have the following query: INSERT INTO `registro`(`id`, `username`) values ('','USER_1'), ('','USER_2'), ('','USER_3') It will add a new user to the…
-
5
votes1
answer1044
viewsHow to bring only a certain part of a text in a field
How do I bring only a piece of text into a field in sql server? I have the query below that in the Description column, it returns a text with a lot of information as for example. Nome Cliente Data…
-
5
votes1
answer164
viewsReturn of SQL command
I need to select in my database all printers compatible with a selected supply, for example, the code supply 155 who is called 50FOZ00. I do the query below to select all compatible printers: SELECT…
-
5
votes1
answer438
viewsHow to join 2 SQL queries into a single one (one is a mean value calculation and another search criteria with BETWEEN
I’m setting up a system that finds providers in a specific region, calculates the average value charged by them and brings this value. But before that he will only pick up the providers that are…
-
5
votes1
answer9809
viewsOracle - Filter by date
I have a column dt_atualiza_log who’s with the guy DATE in the table (is saved in format 01/12/2011 10:10:48) I’m having trouble filtering through and of my query. I’ve tried several ways, the last…
-
5
votes1
answer556
viewsCondition in Select - SQL
I have a table where we store the priorities of output of supplies per customer, for example: cliente | codigosuprimento | prioridade | quantidaestoque 1 | 500 | 1 | 20 1 | 501 | 2 | 10 1 | 502 | 3…
-
5
votes2
answers7405
viewsWhat is the difference between SCHEMA and DATABASE?
I had never used Mysql Workbench and it instead of database, gives me the option of SCHEMA. What is the difference between the two? It gives in the same one or the other?
-
5
votes2
answers172
viewsSQL SERVER - Convert String in Days
How can I convert this string in days? Example: return "2 days and 2 hrs"? SELECT '50:00:00'
-
5
votes3
answers4418
viewsError in a simple SELECT with Group By - SQL Server
I’m trying to do the following SELECT: SELECT P.Nome,P.TipoId,P.QuantidadeMensal FROM StockPhotos.Pacote P GROUP BY P.QuantidadeMensal; But I’m getting this error message: Message 8120, Level 16,…
-
5
votes2
answers212
viewsUPDATE is a DELETE followed by an INSERT?
On another issue (In Trigger we have INSERTED, DELETED, but the "UPDATED"?) this doubt arose as to the form of the database execution, due to the form that the Trigger access an altered record.…
-
5
votes1
answer137
viewsConvert SQL query to LINQ
How would this SQL query convert to LINQ: "SELECT SUM(valor_negocio) valor_negocio, " + " MONTHNAME(STR_TO_DATE(MONTH(data_inicio), '%m')) mes," + " STATUS" + " FROM negocio" + " WHERE data_inicio…
-
5
votes1
answer782
viewsHow to create Trigger for all tables in a bank automatically?
Example scenario I have a database with 1,000 tables. One table call log. Goal I would like to create a Trigger "standard" in each of these tables, automatically. That one Trigger, whenever there is…
-
5
votes3
answers1003
viewsHow to make a select within a condition?
How can I create a script in SQL where a SELECT, and as the result of a column of this first, performs a certain condition of another table? example: select * from tabela as t SE t.saldo = 0 entao…
-
5
votes2
answers2142
viewsLogic to validate free schedules on schedule
good night! I’m stuck for a few days in the following situation, I’m not able to parameterize or create an expression that validates interval between dates, which works like this: that is, if you…
-
5
votes1
answer3432
viewsIs there any risk in using "SET FOREIGN_KEY_CHECKS = 0"?
According to what I read somewhere, the FOREIGN_KEY_CHECKS: ... specifies whether or not to check foreign key restrictions for Innodb tables. I mean, if the guy wants to disable the foreign key…
-
5
votes2
answers67
viewsDifference in performance when Duplicate a table
There is significant difference in performance between these two examples? SELECT * INTO [IP].BA_exemplo.dbo.TabelaB FROM BA_Temp..TabelaA and SELECT A,B,C,D... -- (todos os campos da tabela…
-
5
votes1
answer100
viewsAmount of index influence on performance?
I have a relatively large database. And the consultation in it varies a lot and I have some doubts regarding performance: 1- Create multiple indexes, taking into account the Where (E.condicao = '1')…
-
5
votes2
answers319
viewsWhat is considered when ordering a varchar field? Being filled in by numbers
I have a table with the birthday of the month, for a reason of use here we should store this as varchar. When using it it is necessary to sort by date from the most recent to the oldest, the same…
-
5
votes1
answer157
viewsError converting varchar to integer
By performing the following UPDATE through my API (.NET Core): UPDATE Aula SET WHATEVER = WHATEVER WHERE ID_AULA = @examID Code: string query = builder .AppendLine("UPDATE Aula") .AppendLine("SET…
-
5
votes1
answer9144
viewsUPDATE WITH CASE SQL
Is there any way I can use more than one column of the same table in a case statement in an update? for example, I have this table with these 3 lines create table produto2( codigo int primary key,…