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
answer177
viewsSQL query returning one of the empty columns, different from the database
I’m doing an SQL query, in Oracle database, but one of the fields returns the empty value, different from the table in the database. I have tried to create, and rebuild the indexes, but the problem…
-
1
votes1
answer63
viewsHow to get all the sums of 'SUM'
Good evening everyone, I would like to sum up with the 3 (SUM CASE) below. SELECT SUM(CASE WHEN (a==b 2 THEN 1 ELSE 0 END) AS qtdDba, SUM(CASE WHEN (a==b 5 THEN 1 ELSE 0 END) AS qtdDev, SUM(CASE…
-
1
votes0
answers229
viewsLCK_M_IX in SQL Server database
Guys, I have two distinct client bases in SQL Server 2008, and both using the same system, which uses BDE for connection. I have my own app Scripter to make SQL queries in databases. Problem On both…
-
1
votes1
answer617
viewsDoes query with date in sql include the day in question?
I have a doubt in a matter of the exact days that SQL include, and my system once a day performs the following query on the system: SELECT id,nome FROM products WHERE created_date between…
-
1
votes1
answer2741
viewspg_dump executed via windows command prompt
I executed a dump with the following script: C:\Arquivos de Programas\postgresql\10\bin>pg_dump.exe -h xxx.xxx.xxx.xxx -p 5432 -U postgres -W postgres Senha:... -- PostgreSQL database dump -- --…
-
1
votes1
answer289
viewsDrop or Truncate table with 80 million records?
I have a table with 80 million records, clean it without deleting the table, because it is used in real time, what is the best suggestion so that I can clean this table without losing the…
-
1
votes1
answer97
viewsProblem saving
Only a form that is returning me this mistake, the question that I do not know what can be or how to fix, some ask to cascade the relationship that is already. Nhibernate.Transientobjectexception:…
-
1
votes2
answers499
viewsSql server skipping record id
After changing an application record, the next record I entered in the table skipped 1000 increments in id. id’s 2 3 4 5 6 7 8 9 1015 1016
-
1
votes1
answer1565
viewsBring the first line based on an SQL date
One more challenge stopped in my hands. I need help in my query. What I need: I want to know who are the people who have had account releases on a given day, where I need to show the value and…
-
1
votes2
answers1539
viewsMysql Query with recursive N levels
I have the following query select id, nome, user_id from (select * from users order by user_id, id) users, (select @pv := '2') initialisation where find_in_set(user_id, @pv) > 0 and @pv :=…
-
1
votes2
answers59
viewsQuery to add fields from two tables
I need a query where I will need to add people by color and race, distinctly, for example, make the sum not only by name, but also by color and race alike. I tried something below, but it’s adding…
-
1
votes2
answers58
viewsBring records that is not in another table
SELECT * FROM quiz WHERE status='publicado' AND NOT quiz.id_quiz IN (SELECT id_quiz FROM quiz_resolvido WHERE quiz_resolvido.id_usuario=1) order by rand() LIMIT 0,10; Today I use this Query to…
-
1
votes2
answers570
viewsCreate a VIEW or a new TABLE in Postgres?
Olás! I have a situation... I have a table that will have about 3*10 12 lines (3 trillion), but with only 3 attributes. In this table will have the Ids of 2 individuals and the similarity between…
-
1
votes1
answer200
viewsHow to enter values in Laravel
I am trying to use the following command to insert: $sql = "INSERT INTO tabela (campo1, campo2, campo2, campo4) values(:campo1, :campo2, :campo3,'S')"; $campos = array( ':campo1' => $nome,…
-
1
votes2
answers116
viewsCommand to update multiple tables in the database
It is possible to update my database as follows: My tables in the database have a field emp_codigo ? i would like to update the value of everyone that has in the database to 1 I don’t know if you…
-
1
votes1
answer307
viewsName columns with value returned from Select
I am trying to rename SELECT column with the value returned from another SELECT. Ex: SELECT ID, NOME, QUANTIDADE AS QTDE_4 FROM TESTE Where in QTDE_4, 4 would be the current month. I tried to put…
-
1
votes1
answer294
viewsHow to use SQL instead of JPQL?
This week I went through a problem, to be able to build a Java API using JPQL, but my Java API is not yet completed and I can already predict that in the future my project will need reporting, and…
-
1
votes0
answers101
viewsHow to sort databases alphabetically without accented characters being out of order
I am creating a database in Mysql and want to put some information in alphabetical order. The problem is that when I add the ascending alphabetic order filter, words starting in accented characters…
-
1
votes1
answer461
viewsComment on Mysql table
You can insert a comment in the table equal to the comment in a table field? I need to enter information up to 160 characters in the database tables to help the other devs to have a brief summary of…
-
1
votes0
answers35
viewsMissing right parenthesis
Creating the following table: CREATE TABLE Corrida( Id NUMBER(6) PRIMARY KEY, BairroDaPartida CHAR(30), Valor NUMBER(5), Kms NUMBER(5), Prefixo CHAR(4), CPF NUMBER(8) FOREIGN KEY, CONSTRAINT…
sqlasked 5 years, 7 months ago Gabriela Rosa 19 -
1
votes0
answers206
viewsOracle - Lock preventing SELECT
Lock preventing SELECT The situation is as follows : An ERP application (Totvs) with multiple tables All these tables use as primary key a standard field R_E_C_N_O_ The application (I believe)…
-
1
votes1
answer190
viewsDifficulty in select distinct sum
My goal is to show 1 email with 1 total but I’m having difficulty I’ve tried that code: SELECT DISTINCT email, totalcopias FROM dados https://i.stack.imgur.com/IkU71.png And I also tried this one:…
-
1
votes1
answer62
viewsBring certain record first in SQL query
Hello! All right? I have an image registration system on a portfolio page. In my database I have a table with a column for the image path and a column called main which is a char(1) which can be’S'…
-
1
votes2
answers1075
viewsConnect SQL Server database to Django
I have an SQL Server database that already exists, and I need to connect it to my project in Django. So I come here to see if anyone has already found a solution to the problem, as they still can…
-
1
votes1
answer132
viewsMerge two IF or more
I need to unite some if's and I’m having difficulties, I’ve tried using with the union, but to no avail. The query I’m running is: IF (select count(Estado) FROM tbl_1 where Estado != 'WIP' AND…
-
1
votes1
answer1968
viewsHow to return a table, from a POSTGRES Function?
Hello, I’m trying to create a function in postgres, which at first is all correct, taking the return of function. When I run the function, it is returning all lines, but all only in a field as a…
-
1
votes4
answers95
viewsOptimization in sql
Considering these two tables in the database: Product Table: | id | nome | |-----|-----------| | aaa | Produto A | | bbb | Produto B | | ccc | Produto C | Attributes Table: | id_produto | atributo |…
-
1
votes1
answer53
viewsBlank consultation
I’m starting in the world of programming and at first I have a problem when I run the query locally the query shows me the return normally but when I try to query through a simple application:…
-
1
votes1
answer22
viewsHow to store notifications for performance?
Thinking of a system that at first is small and there is a possibility of a large growth in the flow, what would be the most intelligent/appropriate way to store notifications (a la facebook)? In .…
-
1
votes0
answers28
viewsHow do I mount this select
Good night How I would ride this select 1 - entering the site the premium ads are above the free ones and all Rand -> OK but I need too. Selecting the city, only the state/city premium ads appear…
-
1
votes0
answers45
viewsSaving the user activity in the database(sql)
I am creating a chart to analyze the access of posts by age group by time on my site. But the site does not yet have this ability to capture the activity of the user and need to do it. My task and…
-
1
votes1
answer1962
viewsSQL account how to sum and subtract
I’m starting to learn SQL I need to do an account, I have a select for a report where I need to do an account to show another value in the fields in that report and the formula cannot appear in that…
-
1
votes3
answers250
viewsHow to select only the largest drive in Sql?
I am in need of a help to search for the last move in the stock of each product. It happens that in the clause I made, he is returning me all sales related to that product, and I only need the…
-
1
votes1
answer1994
viewsHow to identify a Job being executed?
Hello.. I created a Job in ORACLE, where it runs a PROCEDURE, but I wanted to perform a SELECT, where I returned the status of this Job. Because I will use this information to return a reply to the…
-
1
votes1
answer66
viewsPerformance of sql server with concatenated joins
Make a INNER JOIN with the keys concatenated, as below, breaks and/or impairs the performance of the bank? INNER JOIN Totvs12.dbo.SE1010 receber ON receber.E1_FILIAL + receber.E1_NUM +…
-
1
votes1
answer54
viewsHow to update a column in the auto increment database and taking into account a sort
I need to update a database table by changing a column with the auto increment value but I must take into account a sort, I managed to update with the following code with auto increment but not able…
-
1
votes1
answer116
viewsHow to total the number of records per Category using a VIEW SQL SERVER
Good night. I’m not finding a way to, using or just calling a VIEW, count how many teachers there are in a certain category, whose output should be the category and the amount. The VIEW I made is as…
-
1
votes1
answer193
viewsReset the priority of a record in the table
I need to update to reorder records in a table in an Oracle 9 database. This table stores records that are requests made by users to IT. So, briefly, I have in the table the following fields: PK |…
-
1
votes1
answer55
viewsNumber conversion
How do I convert a number float to keep the characteristics of numbers for the end user read? I am putting together a report and I wish to deal with the figures. I have a field where the value is…
-
1
votes0
answers804
viewsConversion failed when Converting the varchar value '@userid' to data type int
The error is what is in the title, converting char to int. " Conversion failed when Converting the varchar value '@userid' to data type int." I appreciate any help and if you have any good practice…
-
1
votes2
answers69
viewsHelp with handling employees' schedules
I have a situation regarding company employees' lunch check-in and check-out times; I need to limit the number of employees who can have lunch at the same time, at least together in the 15-minute…
-
1
votes2
answers545
viewsQuery DELETE taking too long to load
I’m having a problem with a query, it has the function of deleting some existing duplicate records in a table. Follows: DELETE t1 FROM bid_account t1 INNER JOIN bid_account t2 WHERE t1.id > t2.id…
-
1
votes1
answer37
viewsHow to group results from a query?
I have the following consultation with the name of the recipe and the ingredients: $query = (" SELECT r.receita, i.ingrediente FROM ptp_receitas r, ptp_receitas_ingredientes ri, ptp_ingredientes i…
-
1
votes1
answer301
viewsWhy is the id ambiguous even creating an alias?
select deals.id as dealid from funnels inner join deals on deals.funnel_id = funnels.id where id = 3 returns 1052 - Column 'id' in 'Where clause' is ambiguous My database is Mysql. Why there was…
-
1
votes1
answer71
viewsHow to create conditional structure in SQL?
I need to create conditions for the attribute nome and idade, which are: For the name: Reject nomes containing the word %mentiroso%. For Age: Reject idades < 1 || > 130. Follow the creation of…
-
1
votes0
answers50
viewsSelect in varchar column containing only one word
How to run a SELECT SQL that only looks for VARCHAR type results that contain only one word? That is, I don’t want results with more than one word
-
1
votes0
answers84
viewsHow to update a sequence to be changed?
Good morning! I have a bit of a boring situation here at work... I would like an idea to solve this problem. There is a case that often happens that is basically the following, When a given customer…
-
1
votes3
answers1052
viewsHow to select different records between two tables
How to select different records between two tables I tried to run the query with the query below; but it did not generate records; SELECT c1.cod_coletor, c2.cod_coletor FROM item_inventarios c1…
-
1
votes0
answers347
viewsMYSQL - Detect sequential break with conditional
Hello I need help to make a query or process to detect gaps in a numerical field, I have a table of tax notes, which has a field num_nfe, it must follow a sequence, there can be no gaps in the…
-
1
votes1
answer121
viewsFiltering data in mysql
I have a table called tb_codes containing the following columns: Cod,txt1,txt2 I need to add the number of characters in the two columns txt1 and txt2, in the example below the character size is 6,…