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
votes1
answer1670
viewsPassing parameters to the postgresSQL
I will create a Rigger in postgresql to copy the information from one table to another, the tables will always have the same structure, so I intend to pass the table names, make a WHILE and copy the…
-
2
votes1
answer601
viewsHow to transform Amble expressions into sql commands?
How can I manipulate expressions to help automate the creation of SQL commands like Linq to SQL? So: using Entityframework I can make queries such as: var livros = contexto.Livros .Where(livro =>…
-
2
votes2
answers1914
viewsHow to make Insert in tables with many relationship for many?
I’m having second thoughts about how I’m gonna do the Insert relationship n:n my tables are: Recibo Analise Analise_Recibo (recibo_id, analise_id)…
-
2
votes1
answer294
viewsString or Cursor in Oracle PLSQL
Good afternoon, I have a precedent that executes a select, but work with a bit map, where I use conditionals to perform a specific select depending on the bit that is passed as parameter to…
-
2
votes1
answer97
viewsGet data according to Mysql date
I need to provide the option to view the data according to an X time determined by the user, for example I want the data from 01/03/2011 until 25/12/2014 How can I do this with Mysql? How do I need…
-
2
votes1
answer393
viewsSeparate Rows by group and their percentage of total
I need to get the top 10 results that appear in my table and their respective percentages by groups. For example the table: +-----+-----+ |id |fruit| +-----+-----+ | 1 | or | | 2 | ban | | 3 | or |…
-
2
votes2
answers89
viewsHow to find a value in several fields
In my bank I have 3 columns for phone, I need to know if the value is in any of the 3 fields, what is the best way to mount this select?
-
2
votes2
answers438
viewsHow to give ALIAS with current "month/year"?
Considering the query below, I need the ALIAS where there are SOMAS, to be "nomeMes/anoAtual" ("ABR/14","MAI/14"...) dynamically. SELECT fornecedor.codigo, UPPER(fornecedor.razaosocial) AS…
-
2
votes2
answers2053
viewsList in each position, the employees who most had change of position
Good evening, everyone. I have a little problem that I’ve been trying to solve for a while and I came to ask here. It is as follows: I have three important entities for this solution: To make it…
-
2
votes1
answer257
viewsCrystal Report with LEFT JOIN and WHERE
I’m having a problem making one LEFT JOIN in Crystal Reports. From what I’ve researched, it’s a classic SQL problem when using criteria WHERE crossing with the LEFT JOIN. I tried to solve every way,…
-
2
votes1
answer2762
viewsAdd values from within a column with postgres
I’m trying to sum the values from inside a column with postgres, the table structure is as follows: id |nome_municipio |valores 1 |Porto Alegre |100.01;95.0;50.1 2 |Ivoti |87.0;80.1;45.1 3 |Novo…
-
2
votes2
answers166
viewsInsert the last table data into a second table
I have a problem to give INSERT in PHP. I have a table called products_1 and another one called products_2. Table 1 has the same products as the second one, but with 5 more products, i.e., ID 11,…
-
2
votes1
answer153
viewsUpdate query with select for Procedure
I’m trying to do a query that will enter a previous but I’m not succeeding, the query is like this: UPDATE sca_lotacao AS t0 SET t0.ativo = 0 WHERE ( SELECT * FROM sca_pessoa AS t1 RIGHT JOIN…
-
2
votes1
answer1120
viewsRetrieve data from fields of the same name but from different tables
I have a select that looks for data from three different tables, but has some common fields between these three tables. My question is how to get the data of these fields, which has the common name…
-
2
votes2
answers441
viewsRecreate tables without dropping
I have an already populated table. In it there is a field not null, which I need to set to null. In graphical mode does not accept and says I have to recreate the table. Is there a way to do this…
-
2
votes4
answers38774
viewsSequential numbering of query results
I’m not really close to the database, and actually I don’t even need such functionality, but just out of curiosity, it’s possible to create in Runtime, that is, during SELECT, a sequential numbering…
-
2
votes1
answer1166
viewsConvert Integer to Decimal in SQL
I have numbers in the database that are in the whole format. Ex:12345 I want to convert it to price format, in real ones. Ex: 12.345,00
-
2
votes1
answer1784
viewsInsert data into table with foreign key
Knowing that I have a table with the fields: [ARQUIVO_GUID] ,[XARQUIVO] ,[TAG] ,[EXTENSAO] ,[URL] ,[IS_STREAM] [ULT_ARQUIVO_VERSAO_GUID] FK [TIPO_DE_ARQUIVO_GUID] FK [DIRETORIO_GUID] FK The last 3…
-
2
votes3
answers516
viewsColumn outside the SELECT WHERE condition
I need to make a query that returns a column with the amount of orders that the customer made within the period past in the WHERE and put together another column with the total orders that the…
-
2
votes2
answers931
viewsSelect returns nothing at all
I have the following method: public DataTable Select(bool all = true, string campos = null) { if (all && campos == null) _sql.Append("SELECT * FROM "); else _sql.Append("SELECT " + campos +…
-
2
votes3
answers163
viewsSELECT filtering the first results
I have the HIGHLIGHT field (yes) (no) I would like to display the results by removing the first 4 results HIGHLIGHT (yes) and display the rest of the records both (yes) from the 4th and (no) I tried…
-
2
votes1
answer61
viewsDuplicate data
I have a table where customers create the budget and to each product inserted a record is made to separate, but I want to make a query by the name of the customer that the system does not take more…
-
2
votes1
answer594
viewsHow to display related table data organized by topics
I have a question in SQL that is the following: I have two tables, the parent table, and the daughter table, where the daughter table receives the id of the parent table as a foreign key, however, I…
-
2
votes1
answer46
viewsReplace in Date inside a FOR
I want to return the last 12 months, the day should come as 01 and need month and year. ex: 2014-12-01 2014-11-01 NOTE: I put yyyy-mm-dd only by a pattern of mine. I’m doing like this: DECLARE…
-
2
votes1
answer35
viewsQuery not identifying value
SQL command: SELECT message, count(message) as amount FROM `messages` WHERE LENGTH(message) >= 4 AND amount < 30 AND message != '#ddd' AND message != 'ddd' GROUP BY message ORDER BY amount…
-
2
votes1
answer209
viewsIF in Storedprocedure within a select, remove sp_executesql @query
I have a Storedprocedure that unfortunately only because of an IF has ceased to be a select and turned everything into a VARCHAR statement and then I run it, losing one of the main benefits of MSSQL…
-
2
votes3
answers98
viewsSearch by selection field
I am creating filters to search for products, having all the products visible, I would like to know how I can make a selection field and by the category that the user chose would only appear…
-
2
votes2
answers584
viewsSort by amount of days missing to win
I have this script in my code: $sql = "SELECT * FROM os WHERE status2 <> 'Fechado' ORDER BY XXXXXXX "; $resultado = mysql_query($sql) or die ("Erro na consulta"); while ($linha =…
-
2
votes1
answer81
viewsUPDATE, field with "placeholder query" failed execution
Follows the code: $campo = $_POST['campo']; $valor = $_POST['valor']; $id = $_POST['id']; $mysqli = new mysqli("localhost","root","","tabela"); mysqli_set_charset($mysqli,"utf8"); $consulta =…
-
2
votes2
answers718
viewsEntity Framework or Stored Procedure
When to use Entity Framework example: var registros = db.Tabela.AsQueryable(); registros = registros.Where(r => (intTipo == 0 || r.IdTipo == intTipo) && r.IdArea == intIdArea &&…
-
2
votes1
answer304
viewsSql Groovy, pass the value of an IN parameter
I have the following code: def pessoaIds = [1, 2, 3, 4, 5] def query = "SELECT * FROM Pessoa WHERE id IN(?)" def pessoaList = sql.rows(query, [pessoaIds]) In this case "personList" returns an empty…
-
2
votes1
answer3770
viewsList tables by foreign key in Mysql
How to identify, by means of an instruction SQL, the tables that relate to another, that is, the tables that have a foreign key that references another table? According to the dummy example, I need…
-
2
votes1
answer44
viewsReturn data from one table if it does not exist in another
I have an environment where there are two forms of login and tables "Users" and "Establishments", these tables are very similar and I need to return this query based on the email typed in the login…
-
2
votes1
answer288
viewsJoint foreign key between index field and a possible string
I am creating an application where I thought of a possibility to insert all existing addresses in the system in a single table, both for users, customers, suppliers etc. the structure of my table…
-
2
votes3
answers633
viewsHow to return the last query ID
I’m working with an Oracle bank I have two tables: Table Student: IDALUNO IDMATRICULA FASE Test Table: IDTESTE IDALUNO IDMATRICULA TESTE STATUS I also have a view that gives me the information of…
-
2
votes1
answer523
viewsError creating a NOT NULL field in PGADMIN " contains null values "
I have a database already created, within it I have a table already created. In it I need to create a field that is NOT NULL. I do everything by the graphical interface that is faster, I click on…
-
2
votes2
answers7215
viewsCreate a column in Mysql that automatically divides the other two column values
People need to explain to me how I can make it similar to what happens in Excel I can create a column in Mysql that divides the values of the other two columns. Something like column 1 / column 2=…
-
2
votes1
answer337
viewsIs it advisable to have a Users table relating to others?
I am beginner in systems development, and I would like to know if the table of users of the system could establish relations with other tables, as for example, the table of company.
-
2
votes2
answers170
viewsCheck UNIQUE element before inserting it
I have a table in a Mysql database where one of your fields (email) is UNIQUE, when entering a record I must first perform a select checking if there is a record whose email field matches the email…
-
2
votes4
answers146
viewssql - SELECT for recent data only
I don’t think my title corresponds to doubt. The application I develop inserts once a month, data referring to the last backup in a table. This table contains the backup instance code, the input…
-
2
votes3
answers183
viewsInsert values from table B in table A if they do not exist
Usually when we work with a insert table based on the select from a tabelaB, we do something similar to this: INSERT INTO tabelaA ( column1, column2, someInt, someVarChar ) SELECT tabelaB.column1,…
sqlasked 9 years, 7 months ago Rafael Barbosa 2,855 -
2
votes1
answer455
viewsHow to make a query with different table conditions
TABLE REGISTER A Attributes: Code, name, type TABLE NUMBER B Attributes: Code, number TABLE PERSON C Attributes: Code, gender I need to bring the information name and type of table A with the…
-
2
votes2
answers401
viewsErro Foreign Key
I’m making a database rather simple for presentation of a work and I’m finding the same annoying problem. In this case we have two tables, funcionario[nome,cpf] and departamento[DNR,CPF do gerente].…
-
2
votes3
answers140
viewsSearch results in 3 tables with the date of the last 5 days
I have the following tables: What I’m trying to do is get the user name that has no record on tbl_votos and no recourse in tbl_recursos in the latter 5 days. I’m using php and mysql.…
-
2
votes2
answers15045
viewscount how many days a date range has in another date range
Good morning, I’m doing a query (mysql) and I have four dates periodo1inicio, periodo1final, periodo2inicio and periodo2final. I need to count how many days of period 2 is contained in period 1. Can…
-
2
votes2
answers841
viewsHow to add a field of a given ID with multiple records?
The story is this: a politician can vote for several zonas, therefore the reason for the same ID candidate contain multiple records within the table. The ID_CANDIDATO being 120000000171, he having 6…
-
2
votes1
answer271
viewsDatabase with extra headers
Does anyone know any database in which, in addition to the traditional architecture (rows and columns), we could create and manipulate FIELDS, which would be available for reading and writing and…
-
2
votes1
answer943
viewsBring "children" record count along to all table records
How do I count how many "children" such a row have, and at the same time list all the records in the table? I have the table categorias, with the following data: _________________________________ |…
-
2
votes1
answer99
viewsReset to auto increment
I have a problem at my base of fingers. I have the sending code as auto increment but whenever I delete a sending code the value not reset or I do not restart will always increase. I wanted to know…
-
2
votes1
answer1250
viewsHow to search for similar words or synonyms in Postgresql
I need to get a survey to return similar words I found the phonetic research it can even be used to refine the search I need, but I think this is not ideal. For example, in a database I have several…