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
-
3
votes2
answers358
viewsHow can I select unique data in SQL?
Hello would you like to know how can I select unique data in SQL? I have an Excel spreadsheet that has the daods that I need to extract information by applying the following filter in sql: GSM which…
-
3
votes1
answer16
viewsEnd of file, incorrect SQL SERVER syntax
I am trying to execute a command in my sql, but always when I try it turns me an End of File error, I already looked line by line and nothing figured out, how can I solve this problem ? DECLARE…
sqlasked 5 years, 9 months ago Lucas Tadeu Egídio Arruda 281 -
3
votes1
answer106
viewsRecursive query to find the Parent item
I have the following question below when making the query in Oracle 10G. I have the table med_item_avaliar that has in its structure items that reference other items within itself (Parents and…
-
3
votes2
answers171
viewsSelect within select where condition exists
Good morning, With a table of articles with the fields Reference | Quantity | Price | Referencesociated | I wanted to have a select that would do the following, with the example: Example Table of…
-
3
votes1
answer725
viewsLogic SELECT CASE WHEN
would like help in building the following logic: I have my main table and two other tables A and B, which have foreign key from the main. When an X column is filled in table A I need to classify my…
-
3
votes2
answers90
viewsUPDATE in a query with multiple entries
I have a query where I have a SELECT from a client ID, and an order ID. Later I perform an UPDATE in a table, changing the tax rate on the selected order. The problem is that a customer may have…
-
3
votes1
answer141
viewsData to string conversion in SQL SERVER
I need to perform a conversion of a query of type date to type string, but it always returns me the following error: Msg 241, Level 16, State 1, Line 2 Conversion failed when converting date and/or…
sqlasked 5 years, 8 months ago Lucas Tadeu Egídio Arruda 281 -
3
votes1
answer126
viewsPerformance according to box control modeling
I am making a system for daily box control, which allows launches/deletion of values. Below is the table that will store the values, filled with some data to exemplify. There are more fields, but…
-
3
votes2
answers245
viewsDoubts in the modeling of the Database
Guys, I have the Product, Ingredient and Sale table. The product contains several ingredients, e.g.: Suppose that the product is a mixture, it contains 1 bread and 2 Ingredient cheeses, this…
-
3
votes1
answer653
viewsIs it possible to make a direct SPLIT in a QUERY (SELECT) in SQL SERVER 2012?
I have the following table below and I need to divide the "Full Name" column into columns in the same SELECT where each column should be filled according to its level. Ex: The Full Name column…
-
3
votes2
answers299
viewsError calling PROCEDURE in SQL Fiddle
When making a call PROCEDURE in SQL Fiddle, the following error is displayed: DDL and DML statements are not allowed in the query panel for Mysql; only SELECT statements are allowed. Put DDL and DML…
-
3
votes1
answer57
viewsHow to do a column search scan with counter bar character
I am trying to perform a query in a table similar to the one below through a field diretorio. +----------+---------------+----------------------------------------+ |id_imagem | data_upload |…
-
3
votes2
answers764
viewsSELECT from the last 365 days (12 months) in sql
Good morning! I’m having some difficulty making one SELECT selecting data from the last 365 days (12 months). What I want you to show is: in the last 12 months you have to show (per month) a number…
sqlasked 5 years, 6 months ago João Simões 98 -
3
votes1
answer96
viewsQuestion with SELECT instruction from a self-relative table
Hello dev’s I own the following table courses(self relational): desc cursos; +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |…
-
3
votes1
answer62
views -
3
votes3
answers216
viewsAs a search for any term removing spaces, traces and points with LIKE
I’m having a hard time changing a search that I have today by searching a code that has, for example this mask A 901.325.0744 the search is correct because the code is registered in this way and the…
-
3
votes1
answer148
viewsGet a result that appears in 1st position if you have a value specified in SQL
I need to create a query that follows some rules and they are: gsm repeat sending be different status who is with ANOMALY and appears as the first result (over the others) I’ll give you an example…
-
3
votes1
answer37
viewsCount twice the number of records from one column to different values using the COUNT(*) function in a single query
I need to count the number of hits and likes per user for different types of content. SCHEMA: secao +--+--------+ |id| nome | +-----------+ |01| Vídeo | |02| Audio | |03| Imagem | |04| Leitura|…
-
3
votes2
answers48
viewsInsert WHERE into query giving error
I have this query here that is pulling right. However, now I want to put those who have the registration only within the current month (for example September). My created_at is datetime. I’m…
-
3
votes1
answer91
viewsHow to use indexes beyond the primary key?
I have a question about that. Consider a table with the following columns: id (chave primaria), cliente, cidade, estado I already understood that a consultation with condition WHERE id = X would…
-
3
votes2
answers280
viewsHow to write this query using Eloquent?
I need to write a specific SQL in a project Laravel but I can’t convert the SQL for the syntax of Eloquent, basically, I need to do this SELECT: SELECT * FROM `movimentacoes` WHERE nome LIKE…
-
3
votes1
answer440
viewsInclude date/time field in postgres (Zend)
I have the following code: View: { xtype: 'timefield', name: 'attendance_time', fieldLabel: 'Hora', inputWidth: 100, format: 'H:i', submitFormat: 'H:i', altFormats: 'H:i', } Model: { name:…
-
3
votes1
answer66
viewsIntervals between two date columns
The problem is this, I have a table that stores the leave (maternity, health, etc...) of an employee, containing the dates of start and end of leave and other information that is not relevant to the…
-
3
votes2
answers299
viewsDo I need to open a Mysql connection for each PHP query?
I need to get several variables based on my bank to mount a full Dashboard. For example, I need the number of lines, the average value of a given field and the same average value only per FU. The…
-
3
votes1
answer231
views -
3
votes2
answers421
viewsWhat is the default sorting (order) of the result of an SQL query?
Suppose I have a table called "student" in the database, and its columns are nome, matricula and curso, your primary key being the column matricula. The column matricula does not have auto_increment…
-
3
votes2
answers65
viewsGET by passing all records in URL and POST Presents only the last record
Good afternoon guys, all right ? I’m trying to create a page to insert items inside a cart, this page keeps the client code and the command code in a variable and passes it between screens, on my…
-
3
votes1
answer47
viewsHow to concatenate columns identified by surname?
I have the following appointment: select case when datediff(...) > 0 then month(tblData.data1) when day(tblData.data2) > 10 then month(tblData.data2) when month(tblData.data2) = 1 then 12 else…
-
3
votes1
answer50
viewsDifference between conventional SELECT and INNER JOIN
Model of the structure of the tables: Tabela: Bancos Cod Nome Tabela: OperacoesBanco Cod CodBanco ValorOp Historico Well I have these two models of SELECT: Example 1 SELECT b.Nome, o.ValorOp,…
-
3
votes1
answer23
viewsHow to count records in the Onetomane relation returning zero when there is no match
Friends, I am trying to make an app to control investments in shares. In DB of this app I have the table portfolio and active table. I need to make a select that returns to me the active portfolios…
-
3
votes1
answer238
viewsTable creation error (ORA-00904)
I don’t know if it’s my glasses that are in trouble, but I can’t see where I’m going wrong. If you can help me. I read that the mistake could be happening by the way I’m declaring mine PRIMARY KEY,…
-
3
votes1
answer47
viewsShow value 0 when no data is available
To show in an sql query, value 0 when there is no data in the table? SELECT ae.dt_data, to_char(ae.dt_data, 'dy'), case when to_char(ae.dt_data, 'dy') = 'sun' then 'Domingo' when to_char(ae.dt_data,…
-
3
votes1
answer66
viewsQuery two tables and display the quantity of the group that has the most foreign key records
I need to make a query between the following two tables: Table Class: id_turma classmate class code 1 1A 20201AVesperto 2 2A 20202AVespertino 3 3A 20203AVespertino 4 4A 20204AVsmarter 5 5A…
-
3
votes1
answer90
viewsHow to limit rows per month in SQL
I have a list of products purchased with date and price, I wanted to organize in a query the ten most purchased of each month, type: mes | nome | total janeiro | arroz | 100 janeiro | feijão | 87…
-
3
votes1
answer52
viewsHow to make a LIKE IN equivalent to PROCV
I have the following question (below is just an example, because I can not send the true info) I want to make a where where I find the name of the social reason by the fancy name of the…
-
3
votes1
answer68
viewsPrevent the insertion by the user of the same number of CPF in three different fields
In a table I carry the number of patient, doctor and attendant. I’m trying to stop the person from scheduling the 3 with the same values. Like: INSERT INTO agenda(cpf_atendente, cpf_paciente,…
-
2
votes2
answers1011
viewsHow to open a report file in RDF format?
They sent me a report with the extension .rdf. The system that generated this report uses MS SQL server 2008 as DBMS. I would like to know how to view and manipulate the information in this file.…
-
2
votes4
answers3156
viewsHow do I create an sql view with more than two tables?
How to create a view sql, I need to get the name and password in the Magento comic that are in different tables, to authenticate in Moodle.
-
2
votes2
answers319
viewsWhat should Query be to get a tuple result where the value of a column is 'x'?
I have the following query: $select = "SELECT concat(mid(cpf,1,3),'.',mid(cpf,4,3),'.',mid(cpf,7,3),'-',mid(cpf,10,2)) as cpf, nome, genero, nome_cracha, rg, crm, crm_uf, rua, bairro, cep, cidade,…
-
2
votes4
answers1443
viewsSQL query that meets a parameter that is a set
I have the following situation: in a MEDICAL CONSULTATION I may have one or more SYMPTOMS. Then I have a CONSULTA_SINTOMA table, making the link between CONSULTATION and SYMPTOM. A disease can be…
-
2
votes1
answer317
views -
2
votes1
answer134
viewsHow to change the Prepared Statement wildcard value?
Suppose I have an appointment with prepare that is this way: select senha from usuarios where id=? //or id2=?, array($id,$id2); (é só um exemplo). My intention is to change the ? by any other value…
-
2
votes5
answers508
viewsQuery error with WHERE AND COUNT on Oracle. "SQL command not properly ended"
I have the following query: INSERT INTO TB_CLASSIFICACAO_UG (COD_CLASSIFICACAO_UG, TXT_DESCRICAO, IND_ATIVO) VALUES (SEQ_COD_TB_CLASSIFICACAO_UG.nextval, 'TESTANDO', 1) WHERE (SELECT…
-
2
votes1
answer1352
viewsError: subquery returning more than one result
Given the sql: DELETE FROM wgcartarmazens WHERE ( SELECT artigo FROM wgcartarmazens as T INNER JOIN wgcartigos as A ON A.CODIGO=T.ARTIGO WHERE T.lote='' AND A.TEMLOTE<>0 ); The above query…
-
2
votes3
answers408
viewsWhat is the best way to create PHP-related posts?
I have a system that I use, but I wanted to have a system to leave more filtered the search for related posts, currently using the REGEXP of SQL to do, I have already used the LIKE and the results…
-
2
votes1
answer928
viewsHow to check if my one-column record (FK) is present in other tables?
I want to delete a record, but sometimes the oracle complains: SQL error: ORA-02292: Integrity Constraint (SGR20_HOMOLOG.TB_CONFIGURACAO_EXERCICIO_T436) violated - Child record found 02292. 00000 -…
-
2
votes1
answer259
viewsHow to pass an SQL expression for an UPDATE to Zend?
My Mysql DBMS has a table called elements where one of the fields is called posicao and is like int (6). I need to update (SQL) where the field posicao shall be updated with its own value by…
-
2
votes2
answers1434
viewsShow users online
Good people I’m wanting to make a system where shows online users at the moment but they are displayed more without restrictions, someone gives me a light $timestamp=time(); $timeout=time()-300;…
-
2
votes1
answer244
viewsMulti-bank Login Control
Well, I have my application and every client will have his own database. As each customer will have their database, they will also have their user table for login. So I have Bancoempresa1 -…
-
2
votes2
answers1836
viewsDuplicate column value, how to avoid?
How exactly do I get this column valueAuxilio does not have its values duplicated, that is, instead of four result lines would be only two. SELECT p.nome, d.nome, c.valorAuxilio FROM sca_pessoa p…