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
votes0
answers96
viewsProblem with changing Trigger
I have a table that receives data all the time, almost every second. This table has a Trigger that after inserting a new row inserts this record in another table. I need to include a new Rigger in…
-
1
votes0
answers708
viewsHow to send the result of a query via email
I wonder if anyone could tell me how I can perform the below query correctly. I need this to be sent to the email showing the result that in the case would be Name : Ariel [select rtstr1 as hostname…
-
1
votes2
answers157
viewsRevoke in TEMPORARY TABLE in Postgresql, is it possible?
It is possible to give a REVOKE (Privilege removal) so users don’t create temporary tables? The CREATE TABLE I need to keep, however, I need to block the TEMPORARY TABLE. It is possible?…
-
1
votes2
answers66
viewsSelect with Join does not return results
I have the following tables livro id int pk passador id int pk fk_livro_id int ordem int I am making a screen listing books. The goal is to bring all the books that are not registered in the dealer…
sqlasked 6 years, 10 months ago Adriano Luz 1,023 -
1
votes1
answer64
viewsConsult results using SQL or tips on programming in XAILER
I have the following relation between 3 tables: 'SELECT contareceber.codcontareceber, contareceber.codorganizacao, contareceber.dtdocumento, contareceber.dtvencimento, contareceber.valortotalbruto,…
-
1
votes1
answer42
viewsIs it better to repeat field or Join to access the relationship?
Hello, thinking about performance and also good practices, what would be the ideal in this scenario? 3 objects: - Enterprise - Person representing the company - Visit (object of a commercial visit…
-
1
votes1
answer322
viewsDelete Button and Edit Fields (PHP,SQL,HTML,CSS)
I’m new here, student of Computer Science and Programming Internship... I do not know much how the forum works, but I have a pertinent question that I have reviewed Google several times and still…
-
1
votes2
answers323
viewsHow to format resultset printing via System.out.println in Java?
Hello, I am printing on the screen the result of a SELECT that I have stored in a resultset object (sql.Resultset). But it comes out "all crooked". I tried to use the " t" between each printed…
-
1
votes0
answers318
viewsIncorrect syntax near the keyword 'ORDER'
I started to perform a program in classic Portuguese and in a part of that program I wrote the following code: <% SQL = " SELECT Id = TCD.Id "_ & " , IdTipoContrato = TC.IdTipoContrato "_…
-
1
votes1
answer1036
viewsRemove Duplicates from Two SQL Columns
So the situation is this, I have a table and in it I have three fields, so I need to compare the (to = b) and see if there’s anyone like it. What my problem, I’m new in the middle of sql and I’m not…
-
1
votes3
answers1182
viewsPagination in PHP
I made the pagination available in the code below, following an example here of the stack, but it does not work as I need it to be: display at most 5 records per page and create the other pages.…
-
1
votes1
answer57
viewsUpdate table so that a field has a unique value
How can I update a record in Mysql so that when I change a field of this record all other records change so that this field has a unique value? for example, I have a table called players and a field…
-
1
votes3
answers4627
viewsHow to return empty record from a Select?
I’m creating a system in PHP and in it has a Script which selects the data of the module requested by the user. The Script creates the form to view and edit the data according to the information of…
-
1
votes1
answer232
viewsCustomize SQL query output
How do I customize an output of an example SQL query resulting from a sum of the columns OUTPUT: 23000 wanted to customize only this output to R $ 23.000
-
1
votes1
answer470
viewsI cannot do a function that returns a Semester of a Date in Postgresql
I’m trying to make a conversion that returns a semester of a date, but this error has appeared here CREATE or REPLACE FUNCTION semestre ( data timestamp ) RETURNS INTEGER AS $$ BEGIN IF data <= 6…
-
1
votes1
answer320
viewsConsecutive sum of a column in SQL
I wanted to calculate the data from a bad table as follows I have a price column 100 140 300 200 wanted to generate a second column that would make a consecutive sum of the previous table 100 240…
-
1
votes1
answer433
viewsIs there any way to use logical operators with CASE/WHEN?
I am trying to use logical operators with CASE/WHEN in SQL but I am having difficulties, I need to present an answer if the result of the operation is less than 0 and another result for when the…
-
1
votes1
answer171
viewsChanging the name of a table in the H2 Database Engine
I’m trying to change the name of a table in H2, but I can’t find the syntax. Does anyone know?
-
1
votes1
answer4217
viewsSave and Use images in database ( Delphi and Mysql)
Hello, I would like to know how to record images (.jpg, .png, .bmp, etc) in the Mysql database, using Delphi XE6. I would like to use Tdbimage, if possible, to display the images already saved in…
-
1
votes0
answers99
viewsHow to pass a query to Eloquent?
I’m trying to translate a SQL for Eloquent, where she receives an id ($myid) and returns the combinations of clothing, IE, I have a table clothes and I have another table combinations_clothes and in…
-
1
votes2
answers87
viewsReplace the second repeated character
I have the following value in an Oracle query. SELECT '3.0.' FROM DUAL I’d like you to return only 3.0 and remove the Last Point (.) I tried to use the REGEXP_REPLACE thus: SELECT…
-
1
votes2
answers90
viewsHow to relate several tables?
Below I put an example I did in excel. How does a select exchanging the values of the table inf_musicas the value of the other corresponding tables? NOTE: I know the basics of SQL, I know you use…
-
1
votes1
answer3026
viewsLeft Join returning only 1 record for each relationship
I need to join between 2 tables where I need only the last record of the 2nd table (only 1 record of table 2 for each record of table 1). SELECT a.Campo1, a.Campo2, a.Campo3, a.Campo4, b.Campo1,…
-
1
votes2
answers2463
viewsMysql select multiple columns from the same table with conditions
I need to select some data from a single table depending on the type of user, for example, a Personal user will have the field RG and PIS while a user will have the field State registration and…
-
1
votes3
answers124
viewsUpdate to CD_SETOR column values in all tables found with column
Using the select SELECT * FROM DBA_TAB_COLUMNS WHERE column_name like 'CD_SETOR' i have as a result many tables with different Owner with the same CD_SETOR. EX: Owner Tables Column Type 210…
-
1
votes1
answer98
viewsORACLE SQL - Sort by sum
I need to make a report and I am not being able to sort it as I wish, I want to select customer debt between 60 and 120 days and sort by total. The code is like this: SELECT SUM(cod_fat_cli)…
-
1
votes1
answer1462
viewsGroup duplicate Sql Server lines
I created the query where I have a table Products and another stock (1:N) need to add the stock of each product has in the stock table, I made the following query: select DISTINCT…
-
1
votes1
answer300
viewsError: Expected End of Statement
I’m using SQL for a classic ASP page and in a part of the code I have this: If (opcao = 1) Then If credito > 0 Then SQL = "UPDATE FO_Passaportes SET creditoTotal = creditoTotal + " & credito…
-
1
votes2
answers21
viewsSwap Tag for another SQL Tag
I have the following email: [email protected], I need to change everything I have meusite.com.br for seusite.com.br. How can I do? My idea was: UPDATE tabela SET email = email "seusite.com.br"..…
sqlasked 6 years, 8 months ago Sr. André Baill 6,946 -
1
votes1
answer129
viewsOrganizing Laravel Migrations into a subfolder is bad practice?
I have created several Migrations that are related to each other, for having foreign keys and etc... but I don’t want to mix them with the Migrations related to auth, Permissions and etc. My…
-
1
votes1
answer117
viewsPerform sub-query with data from a first
Hello friends, a question has arisen, where even entering several forums I did not succeed in Ana it, in this way see if they can give me a "light". I have a main SELECT, and some sub-queries. In…
-
1
votes1
answer58
viewsquery Pdo error (Sort by Count)
I am trying to make a ranking based on the amount of coins each. In descending order. I used this query in Pdo: $ranking = $pdo->query("SELECT * FROM usuarios WHERE banido='false' GROUP BY…
-
1
votes1
answer129
viewsWhen is Trigger SQL server triggered After Insert?
When a Trigger is fired after an Insert and the Insert is within a transaction, Trigger is executed at the time of the Insert or at the end of the transaction?
-
1
votes2
answers4982
viewsHow to count the number of records of a selection in a table
I made a selection of all the results of a table. What I need is to show the amount of these results. In my case, I need to show you how many different specialties there are SELECT "especialidade"…
sqlasked 6 years, 8 months ago Diego Soares 403 -
1
votes2
answers703
viewsHow to make a welcome screen in PHP?
I want to create a welcome page for the user who has logged on to the site. My difficulty is in creating the query as I do and showing the user name through an echo? login.php form <?php…
-
1
votes1
answer112
viewsRetrieve data from a created column
Good evening, I have a table with 4 fields and through them I do some calculations and create a new field to show these same results... The problem is that then I want to get those results and I…
-
1
votes2
answers35301
viewsIF WITHIN A SELECT
SELECT @VL_RET_INSS = SUM(VL_RET_INSS), @VL_RET_IRRF = SUM(VL_RET_IRRF), FROM TABELA WHERE VALOR_TABELA > 0 I would like that when the value VL_RET_IRRF was less than 10 the field @VL_RET_IRRF…
-
1
votes1
answer1107
viewsRegistration in more than one table with Laravel
So, I have 3 tables (doctors, addresses and phones), first I do the insertion in the medical table using the store method that is in its own controller, and I take the id created for it and insert…
-
1
votes2
answers530
viewsHow to make a direct calculation in the database
I would like to calculate the salary of a teacher based on the hourly load of discipline that he teaches, I created a Java algorithm for this, but however I can’t pass it to SQL Algorithm in Java…
-
1
votes1
answer46
viewsSQL - Crossing tables within tables
I don’t know if the title is appropriate, but come on. I have in Table A (table of consulted processes) two key fields (new process and old process) and I have in Table B my variable of interest…
-
1
votes2
answers311
viewsBring the count of the word "DATA" from a column calculated in SQL Server
Good morning, I have a query that brings in a column calculated the information of "Data" and "Historicos", in this column I have the item Prefix (vehicle plate) and the column with the respective…
-
1
votes2
answers3449
viewsGet only last query sql server record
I have the following query: SELECT CODIGO, DTINICIO AS INICIO, DTFINAL AS FINAL FROM PFHSTAFT WHERE EMPRESA =1 GROUP BY CODIGO, DTFINAL, DTINICIO It returns as follows: 0031 2000-11-06 00:00:00.000…
-
1
votes2
answers75
viewsIs it possible to do an Update this way?
I have two tables, the Table Impressoras is where is stored the data of the equipment, as model, patrimony, etc. And I have the table Impressora Local where the location of the printer is stored,…
-
1
votes1
answer949
viewsParameterized query error: Must declare scalar variable
I am aware of the existence of this question: Error in previous "Must declare the scalar variable" But it does not solve my problem. My situation is as follows: I have a common sql query: select id…
-
1
votes1
answer146
viewsSelect does not return broken value
I have the following command: SELECT CAST(450/4 AS DECIMAL(15,2)) Return: 911 where the right one would be 112.5 Because of that? NOTE: My SCRIPT is in a precedent, but roughly my problem is in this…
-
1
votes2
answers378
viewsHow to put simple apostrophes and concatenate with a string?
I have a question, I want to be able to concatenate a String, so that it is interpreted with simple apostrophes between it. For example, SQL would look like this: SELECT IDALUNO, NOME,…
-
1
votes1
answer1231
viewsHow to create this view in postgres?
CREATE VIEW grafico AS SELECT AVG(realizacao) , AVG(estima), AVG(fisiologica),AVG(seguranca),AVG(social) FROM necessidade; I am trying to create a view that brings the average of five columns of the…
-
1
votes1
answer134
viewsHow to return driver names in SQL table?
I have the following tables below, and I would like to return only the name of the pilots who never participated in a race in a Brazilian circuit in the country brasil. Table structure: PAIS (id,…
-
1
votes1
answer623
viewsSystem.Nullreferenceexception: Undefined object reference for an instance of an object
I am developing a project in Asp.net, where I am trying to carry out this insertion in the bank. However when I try to perform this command, I end up stating this error message:…
-
1
votes0
answers52
viewsAre multiple JDBC connections "thread-safe"?
I am creating a very simple java and postgresql project of clients and contacts between clients. Exists the table clientes with id and name, and the table contatos with id1 and id2 which refer to…