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
answer136
viewsSELECT to fill in a field
Good afternoon, I have a table called Pessoa and another Matricula, I need to make a query that returns the fields to me name, license plate and person of them, where name and person are on the…
-
1
votes1
answer90
views -
1
votes1
answer37
viewsQuery returns another user’s value
I am not able to compare the code (from the logged in professional) with the hired code (which should be the same as the logged professional) in sql query and this makes the query return a value of…
-
1
votes2
answers49
viewsUPDATE only in the last inserted rows
I’m importing some Excel spreadsheets via ETL into a relational database. The problem is that in order for me to achieve the relationship of the tables, I am using queries for the insertion of…
-
1
votes1
answer74
viewsHow to determine the type of data to use in this flexible case?
The project consists of a database for RPG sheets (D&D and the like). It was like this: Database record sheet Tables character system raccoon class attribute personagem_attribute Relationships…
-
1
votes1
answer37
viewsHow to pass information in bindvalue with two or more information stored in the variable?
I’m having a problem... I’m getting some id from the database and storing in $ids_cozinha. gave a var_dump and a print_r, is returning me the id I want, so far so good. <pre> <?php…
-
1
votes3
answers143
viewsC# - Know location of database file dynamically
I am making a program using C# in WPF, and I need to access the database dynamically, in this case I am using a .mdf.file. In code I have connectionString like this: string stringConexao = @"Data…
-
1
votes1
answer428
viewsDelete all records from a database except a user
I have a database that I need to delete all records that exist in it, except one user that is in the table User linked to another table (Aspnetusers). I’ve made a few attempts to SSMS, but always…
-
1
votes1
answer98
viewsMulti-layered development and business rule
I work with a team developing an ERP and am responsible for issuing reports, of which one of them runs a select in the bank that in tests took more than 2h running, which led to errors and a big…
-
1
votes1
answer71
viewsHow to Relate a Table to Another Table where the field to relate is an XML
I have an SQL Server database from a system that has been discontinued. In this database, there is a table MOVIMENTACAO and a table EQUIPAMENTO, where would set up a relationship N:N. The problem is…
-
1
votes3
answers283
viewsNo Fill new column as Null, yes with specified value in script
I have a specific table in the database, in it I keep information of classes that are created, swimming classes, futsal classes, weight training classes and so on, it is already in use and with…
-
1
votes0
answers61
viewsCode problem - SQL Developer
The following tables present error: CREATE TABLE REQ_ROB_EQP ( REQ_PER_ROB_ID NUMBER, REQ_EQU_NOME VARCHAR(100), CONSTRAINT REQ_ID_NOME_PK PRIMARY KEY (REQ_PER_ROB_ID, REQ_EQU_NOME) --CONSTRAINT…
-
1
votes0
answers70
viewsDoubt with LINQ to Entities
What would this query look like in LINQ to Entities: SELECT COUNT(cont) qtde_resp , pergunta , resposta FROM pesq_respostas WHERE id_pesquisa = 9 AND Tipo IN ('Intervalo', 'SimNao') GROUP BY…
c# sql entity-framework lambda-expressions linq-to-entitiesasked 5 years, 11 months ago alessandre martins 998 -
1
votes0
answers43
viewsSQL and xp_cmdshell
Good people, I have this little code in SQL: DECLARE @StringRTF VARCHAR(MAX), @Posh VARCHAR(8000) SET @StringRTF = (select traduçao from artigos where Cod_Art='01010066') select @StringRTF SET @Posh…
-
1
votes0
answers36
viewscreate a Rigger to allow you to lend a book only to students who have 'MT' status
the teacher asked to make a Rigger in postgresql, only that can not do no if someone can help me, create Function emprestimo_book() Returns Trigger language plpgsql as $$ Begin if( Insert Loan…
-
1
votes1
answer367
viewsWhen firing an Update Trigger, one of the fields only updates after a second Update
I created a Rigger to inform the fine about the delay of returning rented movies, however, when firing the Rigger once (giving an UPDATE), the field "Total Fine" does not update (only it). But when…
-
1
votes1
answer51
viewsAdd values to a database by PHP
I’m trying to add values to a database through PHP. I am using Phpmyadmin for both databases and also for the site in question. At this point the code I have is the following, I present my doubts at…
-
1
votes1
answer661
viewssave in txt the result of the sql query in Firebird using Delphi
I need to save the result of a query inside the txt file by separating by a delimiter, I am extremely new to Delphi and Firebird, so any help is welcome code below: procedure…
-
1
votes0
answers54
views -
1
votes0
answers46
viewsProblem with Where
I’m using Mariadb and I have a clause problem WHERE bank. The query is inside Excel that brings me database periods through the month filter. But I was asked to change it to a time period, only it’s…
-
1
votes2
answers7225
viewsPostgre query error: ERROR: syntax error at or near "WHERE"
I was working with mysql in this project and the query worked normally. At the moment, I am migrating to postgresql. However, the query stopped working and returned the following error: ERROR:…
-
1
votes3
answers69
viewsHelp with select in MYSQL
I would like to know how I do to list for each city the oldest clients, tried several commands but without success. I would like you to quote automatically. Below some commands I used, however I did…
-
1
votes2
answers52
viewsBD sales record
Good morning. I’m making a sales web app, and I want to return the sales ID to insert into the intermediate sales table (multiple products in 1 sale). I tried that way, but obviously I couldn’t:…
-
1
votes1
answer51
viewsFilter query by removing duplicates
Good afternoon, I’m with the following select: select codemp, codfunc, codevento , vlrevento from sankhya.TFPFOL where codemp = 1 and codfunc = 26 and month(referencia) = 1 and year(referencia) =…
-
1
votes1
answer153
viewsInsert with three tables in Mysql with PHP
For study and testing purposes, I created three tables in phpMyAdmin: People, Contact, Credentiallogin. Contact and Credentiallogin tables are related to People. The goal is to perform the insertion…
-
1
votes0
answers19
viewsjpgraph Empty square php line Chart
Here my code receive data of a form: if(empty($_POST["GESTOR"])) { $where_GESTOR = ""; } else { $GESTOR = implode( "','" , $_POST["GESTOR"]); $where_GESTOR = " and B.GESTOR in ('$GESTOR') "; }…
-
1
votes2
answers308
viewsSort by larger ID and group the similar
How can I list the records by ordering by the latter, but when you have the field related filled, bring the other records with that same value? The general idea is to make a order by id desc and…
-
1
votes3
answers53
viewsCode Duplication in Laravel ORM
I was working and came across the following situation: if (($entrada == null) and ($parcela == null)) { $cotas = Produto::orderBy('credito', 'DESC') ->where('id_subcategoria', $subcategoria)…
-
1
votes1
answer69
viewsTreat a column of the same table twice and present as a record in the same column
Good afternoon Dear Friends, I am developing a report with some necessary standards, I will not delve into the standards for the query, but fact is that I "managed" to make a Query with the…
-
1
votes1
answer1512
viewsSQL use of LEFT JOIN with OR
I’m new to the SQL and I have the following question concerning LEFT JOIN: I have to list a table of cliente where each customer has a id and a code client with another table containing the…
-
1
votes1
answer90
viewsPHP - Bring result with select decimals in the Firebird database
How to bring the decimals (.00) back from my array after the database query using PHP? See the result of the consultation; array(2) { ["COD_PRODUTO"]=>string(9) "AM0038784"…
-
1
votes0
answers381
viewsSQL ORACLE - SELECT inside a Trigger
When I try to run a Rigger that uses this function gives me error saying that the table is changing. Function: CREATE OR REPLACE FUNCTION func_tipo_inst (pCodI t_instituicao.id%TYPE) RETURN INTEGER…
-
1
votes3
answers1491
viewsORDER BY ASC and DESC at the same time
I need the data you have tr_color = success are ordered in a descending manner DESC and those who do not have it, that the column is empty, be ordered in an Ascending manner ASC. I’m assembling the…
-
1
votes1
answer381
viewsBring last date of SQL Product
I am performing the following consultation to bring the products with their last sale date: SELECT P.ID AS 'Código', p.Nome, CONVERT(decimal(18,2),pe.Valor_Custo) as 'Custo',…
-
1
votes1
answer56
viewsSQL query for foreign key null fields
I have a relationship that has the chart: maoObra ( id* , descricao , valor , ... ) And the table: pecas ( id* , nome , valor , ... ) I have another table: ItensServico ( id* , data , pecas_id ,…
sqlasked 5 years, 10 months ago Rafael Christófano 365 -
1
votes1
answer38
viewsRepeat query there is database using for in PHP
I have the following appointment $turmas= $wpdb->get_results( $wpdb->prepare( "SELECT nome FROM turmas WHERE id= '%d' ", $_POST['idSerie']), ARRAY_A ); When I get $_POST['idSerie'] with an…
-
1
votes1
answer106
viewsCount repetition amount of an item
I have a table where were inserted several repeated items, I need to return all these items that have more than one register. So I made the following query: SELECT COUNT(ID), CODIGO, DESCRICAO,…
-
1
votes0
answers64
viewsI am unable to validate the authenticated user
PROBLEM: I am unable to validate the user authenticated by the database. What happens is that when I run my application, putting valid user and password, it returns me false inside my loginOk…
-
1
votes0
answers132
viewsWhy is a hash in Bcrypt different each time it is encrypted? Correct way to compare passwords in Bcrypt
Good, I am trying to create a webpanel and a friend suggested me to encrypt users' passwords with BCRYPT for their security. My problem when trying to sign in, the encrypted password that is stored…
-
1
votes1
answer97
viewsModeling teaching offer database
I’m studying databases and I’ve come up with a problem that I’m not getting out of. The problem is: "A school conducts education level offerings annually. Each year, one or more levels of education…
-
1
votes1
answer236
viewsCount returning null value with Query Builder Laravel
I have a problem, I have a query that searches the employee data plus the sum of vacation days and absences that an employee has. The query is working if the employee has some day registered in the…
-
1
votes2
answers294
viewsTake field letters in MYSQL
I have a field with information in this pattern: "PLC__Line" 34355655413.3912. What can I use to take out the letters, _ and " in a select, leaving only the numbers and the dot? In Postgresql I know…
-
1
votes0
answers63
viewsCatch the start and end of the journey record
I have the following situation: I have the following fiddle, with people’s license plates and registration marks. http://www.sqlfiddle.com/#! 15/1405c/20 I tried to make that second fiddle:…
-
1
votes2
answers63
viewsProblem Trying to query Application c# + Database
I’m making a list of customers, but is returning this error: System.Argumentexception: 'Column 'Cpf_cpnj' does not Belong to table .' This column, Cpf_Cnpj, is in my database: I can’t solve this…
-
1
votes1
answer50
viewsHow to pass a decimal type variable to a string type sql command with decimal separator "."?
I have the following Model class: public class ModelTransaction { public int Id { get; set; } [Required(ErrorMessage = "Informe a data")] public string Date { get; set; } [Required(ErrorMessage =…
-
1
votes2
answers72
viewsHow to include dates even if there is no data
I need to make an appointment at the bank where I count how many vehicles passed in a date range. The code I’m using is this: select date(data), count(if(axlNumber = 2, 1, null)) as eixos2,…
-
1
votes1
answer208
viewsUNION - SQL Server
I’m trying to make an appointment with Union, and it returns the following error message: Message 5335, Level 16, Status 1, Line 1 The type of text data cannot be used as an operand for UNION,…
-
1
votes1
answer1695
viewsSQL how to select in 2 different columns
I’m trying to make a SELECT to select 2 different columns from the same table, example: id | name | tags ----------------------------------- 1 | acao | null 2 | aventura | null 3 | rpg |…
-
1
votes1
answer102
viewsPDO execute returns true but does not insert
I am trying to enter a record in the bank using this code: $sql = "INSERT INTO tb_ConteudoExtra (Titulo_ConteudoExtra, Texto, Id_TipoConteudoExtra, Data, Hora) VALUES ('".$nomePagina."',…
-
1
votes2
answers1011
viewsMsg 8114 error in SQL Server while performing query
I’m having a problem executing a query in the SQL Server, where I try to bring a column with a conversion of done in a column like DATE and another column with an HTML code mounted. Follow the query…