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
votes0
answers266
viewsDelphi sql using coalesce
In Delphi I have Tibquery: select * from TB_PRECO where coalesce(DT_CAMPANHA,'') = coalesce(:DT_CAMPANHA,coalesce(DT_CAMPANHA,'')) and coalesce(DT_VECTOPRECO,'') >= coalesce(:DT_ATUAL,…
-
2
votes1
answer66
viewsSelection with LEFT JOIN
I’m studying sql and I don’t know if this is possible. But I have the following tables: Table contatos ______________________ id | nome | sobrenome | ______________________ That contains only one…
-
2
votes1
answer46
viewsSignaling the last SQL record
I have the following SQL: select cod_nota, cod_local, cod_produto, valor from pedido order by cod_nota,cod_local,cod_produto With the result: |cod_nota|cod_local|cod_produto| Valor | | 501 | 01 |…
-
2
votes2
answers280
viewsSelect from 3 related SQL Server tables
Good, I have the following 3 tables: SELECT * FROM Cartao INNER JOIN Registo ON Registo.ID_Cartao=Cartao.ID_Cartao INNER JOIN Clientes ON Registo.ID_Cliente=Clientes.ID_Cliente WHERE…
-
2
votes3
answers992
viewsBring the latest record with conditional - Postgresql
I have a table with product information (product code, customer code, purchase date, purchase value, etc.) and I need to pull the following information: 1- All customers that last purchase was a…
-
2
votes1
answer82
viewsMerge Names into a line
Good afternoon we use SQL SERVER 2008 as the official database server and we have the following query : SELECT P.NOME AS [PROFESSOR], STIPOCURSO.NOME AS [NÍVEL DE ENSINO], SPL.CODPERLET AS [ANO],…
sql sql-server query sql-server-2008 string-concatenationasked 6 years, 7 months ago Nathann L. J. Lima Alcantara 21 -
2
votes1
answer255
viewsHow to make a weekly mysql query
Good morning everyone! I would like a Help!!! I am in doubt of how to make a weekly mysql query, starting on Monday and ending on Sunday, and the data will be inserted every day, and from the data…
-
2
votes2
answers271
viewsHow to eliminate duplicate lines without using distinct?
The query below returns me the following: IF object_id('tempdb..#tmpHistorico') IS NOT NULL BEGIN DROP TABLE #tmpHistorico END CREATE TABLE #tmpHistorico ( Id int not null, IdColuna1 int not null,…
-
2
votes1
answer350
viewsHow to concatenate a variable plus a message in the "Insert"?
Concatenate a variable and a message in the insert? Example: declare a int; set a = 2; insert into tb_usuario values ('a' + 'fez tal coisa');
-
2
votes1
answer305
viewsjava.sql.Sqlexception: Can not Issue data Manipulation statements with executeQuery()
My key insertion is not being done. And the error that occurs in the console is: java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at…
-
2
votes1
answer189
viewsHow to take the value of an sql record and store in PHP variable
I have an sql table as follows: usuario (`matricula` varchar(20) not null primary key, `nome` varchar(45) NOT NULL, `senha` varchar(15) NOT NULL); In php I’m trying to get the name of a user who has…
-
2
votes1
answer427
viewsPHP - Soap error
Guys good morning, I have a problem with "SOAP" I confess that I am very lay, I already took a look on the internet and I could not identify where this the problem, I wonder if someone could give a…
-
2
votes2
answers143
viewsConcatenate the field and group the rest
I have the following query: SELECT finempe.data_empenho , finempe.num_empenho , finhisem.quantidade , finhisem.historico , finhisem.valor , finhisem.valor_total FROM finempe RIGHT JOIN finhisem ON…
-
2
votes1
answer394
viewsChange the type of a column in several tables in SQL Server
I have a database with 41 tables, in all tables I have a common column to which I would like to assign another dataType. In my case the column is currently varchar(255) and would like to change to…
-
2
votes2
answers52
viewsRandom key during user creation
In my migration of User owning: name, id, email and authorization key, however, I would like to know whether it is possible to authorization key is created randomly during user creation, this key…
-
2
votes1
answer477
viewsError trying to add time field(varchar) sql server
I have a query that returns the following data: SELECT * FROM METAS mes lj saldo meta 4 2 153:59 123:00:00 4 2 25:33 00:00:00 4 2 29:57 08:00 4 2 38:58 45:00:00 4 2 94:47 20:00 4 2 23:41 15:00:00 4…
-
2
votes2
answers210
viewsCross two tables and link the line from one to the other, forming a third
Good afternoon, fellow programmers. I came across the following problem: I have two tables, one with applicants, and the other with vacancies. I need a query that crosses the two tables, and takes…
-
2
votes1
answer207
viewsCheck current date automatically
I’m developing a system in PHP where: I make available an entry contest page for the staff, but this page has an end time, example: The page will be available from today 08/05/18 :17:11 and will…
-
2
votes1
answer541
viewsStorage of List-like variables in an SQL-Server database
Good Evening Everyone, I am developing an application that makes a relationship between a Player and one or more games(online games), the problem is that a game can have one more different skills, I…
-
2
votes1
answer296
viewsSelect returns 2 rows per GROUP BY account
The code below returns the number of marked and the number of served, but when adding the CASE to bring me the amount of absences it separates the line of attendees from the line of the defaulters,…
-
2
votes2
answers666
viewsDELETE WITH LEFT JOIN
I’m having an error trying to execute this command: DELETE doacoes FROM doacoes LEFT OUTER JOIN animais ON animais.idAnimal = doacoes.idAnimalDoacao WHERE animais.idAnimal = doacoes.idDoacao; I want…
-
2
votes2
answers161
viewsHow to remove column fields from a regular expression select?
I need to use a regular Javascript expression to know which columns are passed in a query select. For example: passing "SELECT nome, sobrenome FROM table" the expression would return to me…
-
2
votes1
answer1085
viewsInsert into related tables
Eai personal, to create an SQL for Insert in related tables, are the following tables: tb_Customer(id_Customer INTEGER [PK], nm_Customer VARCHAR, cpf_cnpj NUMERIC) dm_address_type(cd_address_type…
-
2
votes2
answers211
viewshow can I get the last message from my`msg`field with`GROUP BY`
good evening, I wonder how can I bring the last message from my group by, because I’m not getting it. is always bringing the first occurrence of the consultation and I always need to take the last…
-
2
votes1
answer7523
views(Mysql) Insert or Update in the database
I need to perform one Insert in the database, if there is no Cpf of a person. if there is it has to do a Update. But all this through a single script on Mysql. I illustrated the example below as I…
-
2
votes3
answers1428
views(SQL) In parentheses in the WHERE clause
Hello, I didn’t find much information in research I did on... but I am currently having a problem which is as follows: I have an appointment with many simple conditions, just sequences of and. But…
-
2
votes2
answers428
viewsCursor problem: SQL Server
I have a problem with the cursor part: cursor with the name 'Cursobanco' does not exist. Sql code: if @Opcao='1' begin set @tipoPagamento='20' set @LayOut='040' declare CursoBanco Cursor LOCAL…
-
2
votes3
answers628
viewsCreate a custom SQL order
I have a table (groups) in SQL with the following structure: id | name | description | display_order | ... The field display_order was defined as UNIQUE and must be an integer. Its main function is…
-
2
votes3
answers315
viewsHow to mount this SQL to bring months that are not in the list?
The SQL below brings the number of entries made month by month, until then blz. I needed to show the last 6 months, even if it was zero, but in this select it would only bring when there are…
-
2
votes1
answer118
viewsRelational databases and relational object
What are the differences between relational databases and object-relational databases?
-
2
votes2
answers6988
viewsQuery with SELECT and SUB SELECT in Mysql
I have a question about SQL, never worked with sub selects and ended up getting lost with it. My SQL: SELECT CLI.id, CLI.nome, CLI.senha, CLI.email, CLI.cpf, CLI.celular, CLI.data_nasc, CLI.genero,…
-
2
votes2
answers85
viewsAdd rows with the same ID in additional columns
I have the following Table scenario: +-------------------------------------------------------------+ | ID | DATA | PROFISSAO | SEQUENCIA | +-------|…
-
2
votes1
answer153
viewsCount/Dense_rank sql grouped
I’m trying to group the lines by group on sqlserver and as a result I want to: CICLO | CODFIL | CODITPROD | ROW 1 | 1 | 10 | 1 11 | 1 | 10 | 2 12 | 1 | 10 | 3 1 | 2 | 10 | 1 11 | 2 | 10 | 2 1 | 3 |…
-
2
votes2
answers113
viewsMysql select data by period
I’m trying to select data that starts on one date and ends on another, I’m doing it this way: SELECT * FROM vendas WHERE feita_em >= '2019-10-10' AND feita_em <= '2019-10-11' And this is the…
-
2
votes1
answer41
viewsHow to set and manipulate the number of digits in an integer type variable with php?
Good morning! I am building a system with php/sql that works with letters which in a certain part need to generate a 6-digit sequential code that will be for each letter to be sent. letter 1 must…
-
2
votes0
answers458
viewsAccess database getting heavy after running query via VBA
Next, I have a database Access with a table called tblDados. This table contains 19 initial fields. I import a CSV file que contains 1 million records, so far so good, saved and close the database…
-
2
votes1
answer448
viewsDecrease SQL database size [Oracle] - ORA-12953
I am working on a local Oracle XE database. But it has reached the 11 GB limit. ORA-12953: The request exceeds the maximum size allowed for the database, which is 11 GB. It turns out I deleted…
-
2
votes1
answer43
viewsProblems with SQL and cursor
I do not understand why but my SQL code is in error on the FETCH line, more specifically: 'FETCH NEXT FROM c_cursor INTO @idC, @LIT, @LST, @LST, @LIT;' and I do not understand the reason for this…
-
2
votes1
answer59
viewsHow to show in a query records that do not have a referenced datum
I have 3 tables: Person CREATE TABLE Pessoa ( ID_Pessoa INTEGER PRIMARY KEY IDENTITY (1,1), ID_Telefone INTEGER FOREIGN KEY REFERENCES Telefone (ID_Telefone), Nome_PSOA VARCHAR(50) NOT NULL,…
-
2
votes1
answer81
viewsCount in Past Time Intervals
Good morning ! I have a view with contracts, and in it there is a column for Dtiniciovigencia (DATE) and a column Dtfimvigencia (DATE). I needed to count the number of active contracts for each of…
-
2
votes0
answers18
viewsProblems in Sql using Google Api
Before asking this question I looked here and did not find the same problem. I use the Google Spreadsheet as my Database and use the sheetrock + sql library to access the spreadsheet. I can return…
-
2
votes0
answers66
viewsTips to optimize Select in SQL. Does the conditional order in Where matter?
Do you have any tips for optimizing Select in sql? If I search a table with over 500,000 or 1 million records, is there any way to optimize my search so that it doesn’t spend too much server…
-
2
votes1
answer84
viewsSql Procedimento
Good afternoon, can anyone help me create a procedure in the SQL database ? To make a reservation for a room, I have to select a room and declare the Date Entry and Date. What I want, is to make a…
-
2
votes1
answer77
viewsHow do I verify that all data on my list exists in the database?
I need to take the files that are in a list and compare with the files that are in a table in the database, and know if the amount of files that is in my list is the same amount as the table. using…
-
2
votes0
answers175
viewsUpdate within a mysql function
I have to do a process to perform an update on a given table field. I created a function in mysql. But within this function would need to perform an update, but the non-accepted function would have…
-
2
votes3
answers658
viewsCompare 2 field-to-field tables
I have two tables with equal fields. Table A and B I need to compare the contents of the two tables field by field. I am using the following code to find records that have some different field, but…
-
2
votes2
answers1389
viewsHow to avoid invalid date error in a sub-shipment
In the code below, subconsultation "D" returns only valid dates in the DIA column, however, when trying to filter this column using the WHERE clause, Oracle displays the following error message:…
-
2
votes1
answer456
viewsExtract xml tag from a varchar(max) column
Hello, I have a series of xml records in a varchar(max) column and need to extract the tag <MT_USADA>16 MB</MT_USADA>, for example: <?xml version="1.0" encoding="utf-8"?>…
-
2
votes1
answer690
viewsPostgresql autoincrement skips 1 value when Insert is done by a function
I have the following function in Postgresql: CREATE OR REPLACE FUNCTION ve.geraHistorico() RETURNS VOID AS $$ DECLARE i INTEGER := 1; id INTEGER; dataCad TEXT; dataFec TEXT; qtd INTEGER := (SELECT…
-
2
votes2
answers47
viewsProblem with SQL relational logic
Considering this scheme CREATE TABLE bra_ocorrencias ( estado varchar2(2), genero varchar2(1), ano number, nome varchar2(30), num_ocorrencia number ); I need to make a query that returns me the most…