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
-
0
votes1
answer234
viewsConvert VARCHAR to TIMESTAMP (AWS REDSHIFT/POSTGRESQL)
I have the following problem, at source I have the data coming as varchar example of data source in varchar format: 08:15:49 18:16:05 20:01:33 etc.... I need to reinsert this data into a new table…
-
0
votes3
answers80
viewsDoubt with IBM DB2 rule
Guys I’m having a hard time transcribing this sql server structure to IMB DB2. Could someone help me. with cte as ( select CASE WHEN CONVERT(datetime, format( getdate(), 'HH:MM') ) BETWEEN '06:00'…
-
0
votes3
answers222
viewsDecimal problems in the SQL string
I have an error: every time the variable c.Value_do_title passes the SQL string, automatically the "." that separates the Decimal is converted to ",". As you can see in this image, the variable is…
-
0
votes1
answer154
viewsSelect return result even if there is no NULL record, grouped by day
I have a select that returns a data set by DATA. Example: As you can see in the image below, there is no data for days: 20,21,22...28 I would like to bring those lines with result "NULLO" My select…
-
0
votes1
answer43
viewsWhat is the lowest weight direct consultation or using views for a double relationship?
Given the following schema hypothetical: create table cidade( cidade_id integer primary key not null, nome varchar(40) ); create table envios( id integer primary key not null, cidade_origem_id…
-
0
votes1
answer22
viewsAutomation of code
Using a DB2 database I need to automate a query and currently have the following scenario: SELECT * FROM tabela WHERE DATA1 < '2020-06-01' AND DATA2 >= '2020-05-01' How to make date conditions…
-
0
votes1
answer42
views -
0
votes3
answers6516
viewsHow to convert varchar to Numeric in SQL?
I am trying to make an SQL query, but it returns the following error: "Error Converting data type varchar to Numeric." SELECT Tabela1.CPF, Tabela2.CPF FROM Tabela1 INNER JOIN Tabela2 ON Tabela1.CPF…
-
0
votes0
answers36
viewsI need COUNT to return 0
I have two tables with the following data: I want to rescue from the database all users and the amount of jobs they have performed. I was using the following SQL: SELECT u.usuario, COUNT(t.id) AS…
-
0
votes0
answers226
viewsSave a JSON to the database or create an intermediate table?
Good night! I am in a small Dilemma, I am building an application to control events,in this application I have an event that can have several guests in the Front end I am thinking of using a…
-
0
votes1
answer528
viewsLock registry (lock) in SQL Server
Using SQL Server and Delphi, I need to control so that in a certain database table two changes cannot be made at the same time in the same record, I cannot start the update if there is already…
-
0
votes0
answers67
viewsWHERE failure when associating a query column in a view
I am passing some parameters to a view where I need to receive the return of this query. When setting the filters in the Where of my query, the return of the query informs the following error:…
-
0
votes1
answer43
viewsIs giving this error qdo try to add data in table - 00928. 00000 - "Missing SELECT keyword
Is giving this error qdo try to add data in table - 00928. 00000 - "Missing SELECT keyword INSERT INTO DEPT ( DEPTNO, DNAME, LOC) VALUES (10, 'ACCOUNTING', 'NEW YORK'); (20, 'RESEARCH', 'DALLAS');…
-
0
votes0
answers211
viewsRemove quotes when uploading csv
I did the following instruction to upload a csv to the database: public void importarBaseBruta(File arquivo) { try { this.limparBaseBruta(); this.con.conectar(); this.stm = this.con.getStm();…
-
0
votes1
answer32
viewsResolve this database issue
I deduced on doing so, but I believe that with this I only have the information of those who did not trade, could give me a light in this question? SELECT CR.name FROM broker as CR Inner JOIN…
-
0
votes1
answer68
viewsBETWEEN error day 31
Good afternoon, I did some research but I couldn’t find a solution, so I’m asking for help here. My system recovers data released between date ranges using BETWEEN. Using the query to catch the…
-
0
votes1
answer80
viewsHow to make relationship between 5 tables?
I have the following tables: conteúdo, aulas, curso, turma, grupo_User where logic will be the following: Content can belong to several classes, as a class can have several contents A class can…
-
0
votes1
answer566
viewsHow to add equal amount SQL?
I have the following query: SELECT DISTINCT CTRL_CARGA_PED_VENDA.CtrlCargaNum, ITEM_PED_VENDA.PedVendaNum, PRODUTO.ProdCodEstr, PRODUTO.ProdNome, Sum(ITEM_PED_VENDA.ItPedVendaQtd) AS QtdItem FROM…
-
0
votes3
answers200
viewsHow to Merge 3 Select into One
I wonder how I could make one SELECT where I can bring the same resulting however in a single SELECT. Example of the select I need to be single: SELECT COUNT(*) AS QtdTarifados FROM tblLoteTESTE…
-
0
votes1
answer171
viewsError: FROM keyword not found where expected
I am trying to do the following Inner Join but am getting error: FROM keyword not found where expected select e.num_exame as [exame], a.num_amostra as [amostra], e.data_hora_exame as [exame],…
-
0
votes2
answers156
viewsBirthday Ordering - SQL Server
Good night! I have an SQL Server Database with fields: Name and Birth Date. I must sort by the Birth Date, being the order of the nearest date to the most distant date, the intention in this order…
-
0
votes1
answer50
viewsSQL Join multiple tables only the 1st result
I have 3 tables: **clientes** cli_cliente nome 50 A 52 B **telefones_cliente** cli_cliente tel_telefone 50 387 50 386 50 385 52 400 **telefones** tel_telefone tel_contato 385 RODOLFO - COMPRAS 386…
-
0
votes1
answer53
viewsCreate Android Studio Unique Field
I’m a beginner in android development and I’m trying to create a table in sqlite where the value of email will be unique. Only the app is allowing you to register equal emails. @Override public void…
-
0
votes1
answer1891
viewsPerform two COUNT with INNER JOIN
When using the SQL below to carry out the count of the number of brokers in a table using INNER JOIN, works perfectly. SQL: SELECT conta.acesso, count(corretor.cod) as num_corr FROM conta INNER JOIN…
-
0
votes1
answer50
viewsSelect from a column argument with multiple arguments
Good morning, I came across a question I can’t resolve. I have the following code: select id, name, characteristics as characteristic from monsters order by id Return me the following table: id name…
-
0
votes0
answers247
viewsConvert Column to Oracle Lines
Good morning! I need the result of this SQL: SELECT CD_ITEM_PAI, CD_ITEM_FILHO FROM ESTRUTURA WHERE CD_ITEM_PAI = 707534 That at the moment is this: Be that as it may: Can you help me? Using PIVOT I…
-
0
votes2
answers69
viewsMatch table data on Linkedserver servers
I have 3 Linkedserver servers (the 3 having the same tables with the same fields). Server 1: First server Table: Test Server 2: Second server Table: Test Server 3: Third Server Table: Test Select to…
-
0
votes1
answer73
viewsHow do I pass a list of parameters to a precedent?
I want to pass N parameters of N types to a dynamic process. How can I do it? Example: struct = (Here the structure will be mounted with several parameters) struct.id = 123 struct.name='Marisa'…
-
0
votes0
answers142
viewsMultiple return IN and CASE clause using Oracle SQL
I have a situation, using an Oracle-SQL database, where depending on the value informed of a variable (YES/NO), the value being used in the query will change. I tried as below but returns the error:…
-
0
votes1
answer42
viewsHow to insert multiple email addresses within one variable, in SQL?
For example: If instead of just typing an email address in the variable below, I typed 30 email addresses, which I would have to change in my query below? DECLARE @email as NVARCHAR SET @email =…
-
0
votes1
answer47
viewsBest Script Performance
I made a condition that way: If @dt_contabilizacao = @dt_operacional And Not Exists (Select 1 From tabela Where dt_mes_referencia = @mes_referencia) But the check of dt is not necessary since if…
-
0
votes2
answers335
viewsUnion problem in mysql
I am trying to perform a query and is giving the following error: Unknown column 'BRANCH' in 'field list' The consultation is as follows:: SELECT TICKET, DATAHORA, TIPO, ESTADO, CRITICIDADE, LOGIN,…
-
0
votes1
answer330
viewsConsolidate all columns into one MYSQL row
I’m trying to make a query that groups all the results in one line, that is, that does not bring duplicated results. I’ve used the distinct and the group bybut one of the two has returned what I…
-
0
votes1
answer50
viewsCoverter Int in Vachar - Mysql
Personal talk Good afternoon. I’m making a list of columns in my Files table. And I needed to convert a "Id_folder" column of the INT type into Varchar at the time I Brought the data after the query…
-
0
votes1
answer42
viewsSQL connection to PHP
I have the following PHP, I am using WAMP, and as in the image below, dll’s are active: <?php $server = "dblinx"; $connection = array("Database"=>"Linx", "UID"=>"root","PWD"=>"root");…
-
0
votes2
answers379
viewsSQL connection with PHP does not find the Drivers
I have the following PHP: <?php class Conexao { private static $connection; private function __construct(){} public static function getConnection() { $pdoConfig = DB_DRIVER . ":". "Server=" .…
-
0
votes0
answers40
viewsIs it possible to select periods from a table in a select without subquery?
Greetings, I wonder if it is possible to select a table period without using a subquery as an example below: Select Usuario, Divida.Janeiro , Divida.Fevereiro, Divida.Marco ... from Usuarios a left…
-
0
votes0
answers440
viewsError executing a Trigger ORA-04092: not possible on a trigger
I have the following problem: - I’m not able to perform a job (Scheduling) after an Insert rescued by Trigger. Row 2: ORA-04092: not possible on an ORA-06512 trigger: in "SYS.DBMS_ISCHED", line 135…
-
0
votes1
answer232
viewsDynamic php SQL Server Quiz
Hello, I am building a calibration tool (given a Checklist the user needs to select the fields that are in agreement (or not) with a link or script. Ex.: 1)Colaborador inicia o atendimento conforme…
-
0
votes3
answers101
viewsMysql printing multiple times
I’m having a problem printing Mysql data in Eclipse. When I put to print the list of registered data it is printing 3 times each information. I know where the problem is, but I can’t see the…
-
0
votes0
answers198
viewsFatal oci_connect error
I have a bank oracle which is on a virtual machine, and I’m doing a university job I’d like to connect this web system to that bank. Here comes the doubts, I need to install some application in the…
-
0
votes1
answer129
viewsJoin Mysql tables
I have a table that has the times of the day SELECT * FROM horas The type of the column hora is VARCHAR(5) And a query containing the values of the hours SELECT DATE_FORMAT( date, '%H:%i' ) HORA…
-
0
votes1
answer131
viewsHow to create a Mysql Trigger with more than one cursor
I’m trying to update two tables using the same Rigger, but it only updates the sales table, but no errors occur. Follows code: DELIMITER $$ CREATE TRIGGER depoisInsertNotas AFTER INSERT ON notas FOR…
-
0
votes2
answers113
viewsHow could I improve this SQL query query with sub querys?
There are many sub selects, how could improve this query in Mysql and make a max SUM of total_points_period'? Pick up the total points for a period from the "user_bigdata" table and the total points…
-
0
votes1
answer78
viewsHow do I complete SQL table name with a variable value?
I want to create a new table for each client and I want to complete the account table with the client id I am creating in another table as in the example below: await db.run('create table if not…
-
0
votes1
answer54
viewsSelect do not return repeated based on a column
I came across a situation where I have a register of customers who may have more than one address in the related tbEndereco table and an address may belong to more than one customer. But when…
-
0
votes1
answer467
viewsHow do I make an INNER JOIN conditional?
I have the following SQL that displays me only properties that have a registered photo, as specified in the lines: INNER JOIN fotos ON imoveis.id = fotos.cod How to display real estate with or…
-
0
votes2
answers27
viewsSet a specific order in the query
I have a query that selects all group members in rank order (owner, administrator and member) and by the date when the member joined the group. By the column access_level not being numerical I don’t…
-
0
votes0
answers312
viewsMessage 8115, Level 16, Status 5-Arithmetic overflow error when converting Numeric to data type scan
I can’t find what’s wrong with these conversions : INSERT INTO @RESULTADO SELECT @DATA_REF as data_ref, @EMPRESA as empresa, @LOCAL as local_loja, Month(@DATA_REF) as mes, Year(@DATA_REF) as ano,…
sqlasked 6 years, 4 months ago Artur Bruno 1 -
0
votes1
answer58
viewsResult of the come zeroed query
Good Afternoon, I have a question, could you help me? ... What happens is: I have an sql query that brings me the total amount of sms sent per month and year, but I would like when I had not worked…