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
answer110
viewsDynamic insertion according to date and days of the week
I’m creating an application using webservice in PHP. Within the application the user will set specific days to generate an alert, for example: second fourth sixth In this way, I would like my bank…
-
1
votes1
answer250
viewsCreating a "check" method in a DAO class
I have a question when creating a method that checks if there is already a record in my database. In my database I have two tables: Table User: (id, login, password); Order table: (id, Qtd,…
-
1
votes1
answer1031
viewsHow to set a maximum size for a BLOB field?
I want to insert images and I want each record to have at most 100M, if this value is exceeded should be returned an error in the database itself. For example illustration of the problem: (in the…
-
1
votes3
answers1184
viewsRead an Array or Bulk Collect as a table in an Oracle PLSQL
How to load an Array or Bulk into a PLSQL and then read this as a table. Example DECLARE VA_ARRAY ....DEFINIÇÃO DO ARRAY VN_QTD NUMBER; BEGIN -- TABELA01 É UMA TABELA FÍSICA EXISTENTE NO BANCO…
-
1
votes0
answers87
viewschanges in linked tables (CASCADE etc...)
I am learning MYSQL on my own due to the teaching restriction that there is in my city and its vicinity, so I would like information on how to use CASCADE in the table that I have with this…
-
1
votes1
answer265
viewsIdentify and archive old Mysql records
I am working on a project using database in MySql where some areas will be constantly fed generating a high number of records in a short time, such as an area for maintenance tickets. However, these…
-
1
votes0
answers82
views -
1
votes0
answers52
viewsDifficulty with Weekly Agenda Display
I am trying to create a weekly schedule that displays the scheduled classes of each day and time, and also leaves the unscheduled schedules vacant. I developed the following code to record all class…
-
1
votes1
answer96
viewsHow to execute a select within an IF/CASE condition?
would like to know how I can use a select as a true or false condition within a case or IF: The query to return true or false is this: SELECT * FROM Funcionario f WHERE (f.Email IS NULL OR…
-
1
votes1
answer142
viewsHow to join 4 tables in SQL that is returning empty ? (Inner, Outer or left Join )
I have 4 tables with the following relationships: Products has N Variations Sizes has N Variations Colors has N Variations Variations belongs to Products,Sizes and Colors The structure of the tables…
-
1
votes2
answers402
viewsSQL/Java query
Good morning, guys I am beginner in SQL and I need to do the following search. Tenho esta tabela: MINIMO MAXIMO CLASSE 0 20 1 21 40 2 41 60 3 60 10000 4 I need a command to see which class fits the…
-
1
votes2
answers1514
viewsCalculate length of a Sqlserver field
Hello, I have a table in SQL with the word column and a column sizeDaPalavra, I was wondering if you have any way to register the word in the database and execute a function that calculates the…
-
1
votes1
answer451
viewsSort result of a JOIN query based on the number of records in one of the tables
Assuming I have two tables in my database (pedidos and pedidos_itens) how I can obtain data from requests ordered by orders containing more items? I’ve tried to make a Right Join, but I don’t know…
-
1
votes1
answer1040
viewshow to take data from one mysql table and insert it into another :?
I’m trying to do brush validator (serial), but I don’t know how to do it. I have two tables: "validation" and "maturity". In the "validation" table, you have the following fields: id(int),…
-
1
votes0
answers78
viewsOptimization of SQL query time
I have a database that stores precipitation marked by various sensors on certain dates and times over the course of a year. I am making a query, to search all records marked by a single sensor, with…
-
1
votes1
answer355
viewsProblems getting value from Resultset
I’m trying to get the values of a select in the derby but they just returns correctly a field from Resulteset. Follow DB access class code: import java.sql.Connection; import java.sql.DriverManager;…
-
1
votes1
answer91
viewsList records without reference in another table
I have three tables: -customers -plans -services On the table services have servico_A, servico_B and servico_C that are related in the table plans. I need to list all customers who do not have a…
-
1
votes2
answers718
views -
1
votes1
answer60
viewsWhat’s wrong with my Mysql code?
The error is this: error code 1064. You have a error in your sql syntax; This is my code: INSERT INTO pessoa (Endereço, Email, Telefone) VALUES ('Rua Ernesta de Oliveira Pina',…
sqlasked 7 years, 12 months ago user61821 -
1
votes2
answers354
viewsUpdate command does not update table
I’m having trouble with my CRUD. My code searches in BD and returns me the data on the screen correctly, the problem that when I saved, it does not update the BD and also does not display any error…
-
1
votes2
answers93
viewsGroup views in SQL Oracle
I’m having a little logical reasoning block. I have a table (Tabela1) organized this way, but I would need to return the query as the table2 below. Someone can help me?…
-
1
votes1
answer41
viewsREAD PHP - mysql_fetch_array
Hello, I would like a help with the command below. I am trying a read in a database table but I cannot do the while, because it only shows the last record. Note: Using the vardump she shows the loop…
-
1
votes1
answer983
viewsException SQL Oracle - Update and Insert
I have a question regarding a precedent that I am making oracle bank. A small explanation for what I am doing: I am reading data from a table, and throwing them on a cursor, after playing on the…
-
1
votes1
answer54
viewsDoubt with "pivot" ORACLE
I would like to know how to put the fields CODIGO_PROCESSO, NOME_PRODUTO_PROCESSO and APROVADO_USO in the main select to show in my query SELECT CODIGO_PROCESSO, MAX (DECODE (tipo_arquivo, 'BT',…
-
1
votes1
answer648
viewsHow to display a result using 2 selects
I have two table, Products and Orders. I need to create a combobox for products and when the user choose a product, the page has to display all orders related to the product, if I choose another…
-
1
votes1
answer354
viewsHow to convert mysql search result into columns
Good evening guys, I do not know if someone has been through this, but I need to convert the result of a search in mysql in columns, is not to exchange the rows for the columns, but rather, make…
-
1
votes2
answers550
viewsNull value showing zero MS Access
I need to set a field in Access to Null, through SQL, but after setting this field, it gets the value Zero and not Null. Due to a business rule, I need this field to be NULL and not Zero. The field…
-
1
votes1
answer5997
viewsCurrency format
To be complete I could not enter a FORMAT(Value,2) including in CONCAT? SELECT * , CONCAT('de ', Valor, ' por ', desconto) AS promocao FROM (SELECT Valor, Valor - Valor * 20/100 AS desconto FROM…
-
1
votes2
answers1597
viewsQuery per month and year (Php + SQL)
I have a system in PHP where I use the datatables plugin, I can sort by date, but the user wants to stipulate the period for consultation, for example: Select from 01/01/2016 until 01/31/2016 and…
-
1
votes1
answer200
viewsIs it possible to select a table column without entering its name in SQL?
So I was researching but I couldn’t find anything about it, but I need to sort of select the first and second column of the table, without knowing what they are. My code is this: <?php…
-
1
votes0
answers203
viewsNpgsql failed to call plpgsql function
I’m running some tests on the Npgsql. One of the tests tests the return of a plpgsql function. But the test is failing saying that the function does not exist. In the error description the name in…
-
1
votes1
answer190
viewsSQL: Record counter with grouping of data from different fields
I’m having a hard time building an SQL. have a table addressee with the strings fields street and crossing. I need to count the numbers of records that have the same crossing and group them Example:…
-
1
votes1
answer131
viewsHow to average in SQL?
I have a job to do where I insert name and two notes into a database using Voicexml. I have two tables, one with nome, notaum, notadois and another with nome, media. How do I calculate the average…
-
1
votes1
answer46
viewsQuery does not return all record data
The following query returns the correct record, but missing items on its return. $nota = $this->Nota->find('first', [ 'conditions' => ['id' => $numero, 'serie' => $serie ] ]); For…
-
1
votes1
answer136
viewsMAMP - phpMyAdmin - Error
When I go into phpMyAdmin through Mamp, this error occurs: phpMyAdmin - Error Error During Session start; Please check your PHP and/or webserver log file and configure your PHP installation…
-
1
votes1
answer63
viewsHow to make modification records in a Mysql Table (without using triggers )?
I wonder if there is another technique to make records of modifications in the tables without going through triggers ?
-
1
votes2
answers389
viewsMD5 is good enough?
I’m working on a legacy system, which has a database with about five years of accumulated records with no normalization. Among other things, its purpose is to allow users to write and post posts in…
-
1
votes1
answer150
viewsTo display the day of the week of any date in the last 1,000 years
I used this command select to_char(to_date('18-apr-1972','dd-mon-yyyy'),'day') day from DUAL; but gave error in execution: ORA-01841: ano (completo) deve estar entre -4713 e +9999 e não pode ser…
-
1
votes2
answers105
viewsJoin repeats records again?
I have tables in the database that relate. A (t.a) has four lines that relate to the other four lines of (t.b) The query is made by means of a (user.id) that exists in the two tables. The problem…
-
1
votes1
answer89
viewsDrop Index with SQL variable
I’m an inexperienced grasshopper and I’m looking to make an automatic script for myself. This script I created in batch and I can go smoothly to the installation of SQL, database restore and…
-
1
votes1
answer375
viewsCalculate average with Pivot result
I have a query that returns the grades of students in certain tests. The amount of test may vary. I use the Pivot command to transform test names into columns and so organize test/note, as shown in…
-
1
votes2
answers1153
viewsLeft Join with multiple fields from the same table
To build a lease, I have two tables. The first is the contract, has some relationship fields as id_locador, id_locatario, id_fiador1, id_fiador2, among others. These fields are related to a table of…
-
1
votes1
answer431
viewsQuery to turn columns into records
I have a query that involves several tables in Oracle, and returns a large number of columns. I wanted instead of returning the records of this query, return me the columns of select as records. An…
-
1
votes1
answer1799
viewsDuplicate records in SQL - Oracle
Good morning, I’m new here and I’ve got a boring problem. Distinct does not solve my problem because the duplication is due to the fact that I had to make the relationship with other tables to seek…
-
1
votes1
answer136
viewsINSERT inside WITH clause
I basically learned SQL from Postgresql, I’m making use of SQL Server for the first time and I couldn’t figure out how to do it. Let’s say I have two tables. The first is a generic table of…
-
1
votes2
answers449
viewsHow to create summation with "sum" with multiple queryover columns
People need to create a query with queryOver(Nhibernate) C#, to add more than one column. Example in pure sql: SELECT SUM(coluna1 + coluna2 + coluna3 + coluna4) FROM tabela First I did so: Tabela…
-
1
votes2
answers827
viewsRemove duplicated data and return the highest value date field
We are migrating signatures from an Access database to Mysql, but before migrating I need to process some parts of the data. I need: Remove duplicate id’s Return the highest value of the date field…
-
1
votes2
answers888
viewsHow to compare 2 cells in different columns - SQL
I need to make a SELECT searching some data with the condition that only if the value of a given cellis different from another cell. Ex: +-----------+------+------+ | Descricao | Val1 | Val2 |…
-
1
votes1
answer1291
viewsDynamic access column oracle cursor
I have a situation where I need to access the attributes of a cursor differently. I have a cursor that returns me a list of records, with columns like col_1, col_nova, col_teste (illustrative…
-
1
votes1
answer158
viewsRemoving "BC" from Timestamp dates in Postgresql
Hello, I’m trying to remove "BC" from sql dates but I’m not getting. I’ll tell you what: SELECT CAST("regiaulaavul_dataInicio" AS date) FROM "RegistroAulaAvulsa" And eventually return me the date…