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
-
5
votes2
answers880
viewsDuplicate value in table. How to remove?
I inserted some TSE tables in my database and have duplicate column values SQ_CANDIDATO representing the image above. How can I do a maintenance with sql who will remove ALL the duplicated values…
-
5
votes1
answer309
viewsRetrieve information about which Tables/Procedures/Views are most accessed in SQL SERVER
select db_name(database_id) as banco, object_name(object_id) as objeto, stats.user_seeks, stats.user_scans, stats.user_lookups, stats.user_updates from sys.dm_db_index_usage_stats as stats I have…
-
5
votes1
answer1178
viewsHow to filter a SELECT with n:m and bring all characteristics?
I’m using n:m to create a system of attributes/characteristics for certain products, so I can reuse the same attributes for more than one product, the table is something like: When I run a SELECT…
-
5
votes3
answers7043
viewsHow to make a left Join using a Where condition?
I have two tables: category -------- id | nome | imagem user_follow_category -------------------- id | from | to | date Note: the relationship of the two tables is given by category.id and by…
-
5
votes1
answer209
viewsGet Rows that are not from the logged-in user
I have a table with columns para and de where I enter different Ids in each one, but I need to get the ID of the user who SENT the request to me, ie the ID that is not the same as the logged in…
-
5
votes1
answer1187
viewsError in PDO query
I am creating a registration page where I have several tabs, as the structure below: <div> Aba 1 </div> <div> Aba 2 </div> <div> Aba 3 </div> <div> Aba 4…
-
5
votes1
answer751
viewsIndexing of Database
What is the advantage of maintaining an indexed database, with Foreign key and indexing of the most used fields as in searches?
-
5
votes2
answers1099
viewsHow to remove formatting from the GETDATE() command
I am developing an application that will be used by several customers simultaneously, I would like to use as id the Day, Month, Year, Hour, Minute, Second and Millisecond, would have as I remove the…
-
5
votes3
answers11223
viewsWhat is the MINUS command for and how it works on oracle
I’ve never seen this command before and I haven’t found it here either, I don’t know if it has another name and from the Oracle documentation I couldn’t understand exactly how it works. I just want…
-
5
votes2
answers303
viewsLogic ports in SQL
Is there a command that represents the logic gate XNOR or NOR in SQL? Something that for example denies XOR output
-
5
votes2
answers466
viewsFind out which table the data is from, in a Union
Hello, I have a php system, using codeigniter, and in it runs the following command: $data['dados_tabelas'] = Tabela1::find_by_sql('SELECT * FROM tabela1) UNION (Select * from tabela2)'); That’s…
sqlasked 9 years, 5 months ago Jonathan Machado 283 -
5
votes1
answer2036
viewsWhat type should I use to save only the time (no date) in a database?
I am in doubt which type I should use to work with hours on my system. I should use DateTime, Time or TimeStamp. I would like the hours to be saved in this format: HH:MM…
-
5
votes1
answer601
viewsCan foreign key be null in Entity?
I’m having a hard time in a project. I created two tables (Union and Schoolhouse), whereas the PK table Union is FK on the table Schoolhouse. But this FK may be void, i.e., the Schoolhouse may…
-
5
votes1
answer3246
viewsHow to define predefined types in Mysql?
In the site I’m developing I will, for example, a registration form where the user should define their gender in a combobox (male or female). The table users in the database will have all user…
-
5
votes1
answer203
viewsSWT using DATETIME problem in saving compatible SQL format
The problem is this: I have a personal finance program that will register some important data, among them the registration date and the due date. Program interfaces are made in Eclipse at SWT, and…
-
5
votes4
answers6626
viewsWhat SQL command shows the maximum number of active connections to the Mysql database?
Which SQL command returns the number of active connections to the database?
-
5
votes3
answers160
viewsDo not fill in field if it does not exist
I have a question on how to ask a question to the database. Suppose I have two tables with slightly different structures Table1 id tipoA data 0 A '21/12/14' Table2 id tipoB data 1 B '24/12/14'…
-
5
votes2
answers157
viewsWhat’s position on Sqlserver?
I have a question. I received the layout of a table containing: Nome do campo | Tamanho | Posição | Tipo The Position contains: De | Até And one of the fields is: Histórico ( no caso da Posição ):…
-
5
votes1
answer310
viewsData link in SQL
I don’t really know almost anything about databases and the like, but I’m doing an "admin" system here for a client and I wondered about the following point: I have two tables, one that saves the…
sqlasked 9 years, 4 months ago Backend FG1 51 -
5
votes1
answer92
viewsError with Like do sql
How do I extract all fields starting with '1. ' from the BD? In my instruction I used the LIKE but had no return, but to remove the point already returns something, but returns fields I do not want,…
-
5
votes3
answers747
viewsWorking with ID limit on large volumes
I have in mind some questions about large volumes of data on MYSQL, concerning the limit of ID. I will give as an example ID guy tinyint to simplify the explanation. In the example the field tinyint…
-
5
votes4
answers9200
viewsQuery using like operator
In a query in the database I inform the keywords, the month and the year. I want to get the data according to the keywords, the month and the year. For example: the word school on date 2015-08. For…
sqlasked 9 years, 3 months ago André Nascimento 1,258 -
5
votes1
answer1630
viewsSaving a JSON in Database vs Relationship?
When I didn’t know much about the question of database structure and relationship between tables, I used to use JSON or comma-separated data in a given field of any table in the database. In fact, I…
-
5
votes3
answers2237
viewsChange column to indentity using T-SQL in SQL Server
I need to change an existing column in a table so that it stays with the property identity using T-SQL and then entering data into this table. The column already contains data and after this…
-
5
votes2
answers8376
viewsConvert a positive decimal number into negative
I have the following query: Valor1 = '200.000,00'; select Valor1 from TB1 Is there any function that converts a positive number to negative?
-
5
votes1
answer151
viewsIs there a way to name the selected tables from a stored database to identify them in the Dataset?
I have a Store Procedure in SQL Server that projects various data. Example: CREATE PROCEDURE [dbo].[teste_sp] AS BEGIN select * from compra select * from cliente select * from fatura END However,…
-
5
votes4
answers1917
viewsHome Time in SQL (Years, months and days)
I need to create a SQL function that returns the employee’s home time, example: years old, months and days So far I’ve managed to bring the years old and months, but I couldn’t get the logic of day…
-
5
votes2
answers1455
viewsHow to create this rule in mysql
I have a field on my table: tipoEndereco char(1); But this field only receives two possible values, which are: 1-> i (Instalação) 2-> c (Cobrança) Because of that, I’m thinking, and I’d like…
-
5
votes2
answers168
viewsClause similar to Mysql LIMIT in MSSQL
I need to run the query below in PHP with SQL Server, however I cannot use the clause LIMIT absent in darlings microsoft. $SqlTabelaAtual="SELECT * FROM BusinessCadTabPreco RIGHT JOIN…
-
5
votes2
answers731
viewsSQL - Double UPDATE with double Where
Next, it is possible to make two update-where together in the same consultation? I will explain, what I wanted to do is the following: UPDATE usuarios SET nome = "Matheus Silva" WHERE id = 1 AND…
-
5
votes3
answers1803
viewsTables/Temporary content in the database?
Situation I am wanting to manage a process using the resources that database offer, as INSERT, UPDATE, DELETE. However all this process is temporary, that is, I have to generate tables and data that…
-
5
votes1
answer8184
viewsIs there anything similar to WITH(NOLOCK) of SQL SERVER in ORACLE?
I recently discovered in SQL SERVER the option of not blocking tables for insertion while reading some data, and with this gain some performance in some specific situations. I searched, but I did…
-
5
votes3
answers21403
viewsTurn rows into columns with their respective values
I have the following table idRegistro|Campo |Valor 1 |Nome |Zonaro 1 |Email |[email protected] 1 |campoX|valorX 2 |Nome |Fulano 2 |tel |1188889999 2 |campoY|valorY I need to create a select that…
-
5
votes3
answers2025
viewsHow to save a Base64 image to SQL and save it locally as PNG
I need to know if it is possible to save a Base64 image in SQL and then retrieve it and save it locally as PNG or JPEG. I already know how to convert to Base64, but to download in all browsers this…
-
5
votes2
answers1913
viewsQuery to pick text after a certain character
Good morning, I need a way to get all the rest of a string after a certain character, for example, I have the following database I always need to find what’s left of the string after the last "»"…
-
5
votes2
answers207
viewsProcedure "complex"
Hello. I’m learning procedures and I have a question: DELIMITER $$ CREATE PROCEDURE `atualiza_telefone` (IN telefone INT) BEGIN IF (telefone IS NULL) THEN SELECT * FROM cliente; ELSE UPDATE cliente…
sqlasked 8 years, 8 months ago Mateus Binatti 401 -
5
votes3
answers5377
viewsSELECT IN A RELATIONSHIP WITH SELF RELATIONSHIP(Verifying Conflicts)
I’m having trouble making an appointment. The situation is as follows, I need the bank to return all the names of the disciplines that have no prerequisites and that are not prerequisites. This is…
-
5
votes1
answer124
viewsIs it a good practice to have the same name with the column name of the bank?
Let’s say I have one input text de name="txtnome", it is a good practice to have a column of the same name as this input on my table? Being that I’m using PDO for CRUD $st…
-
5
votes1
answer124
viewsUpdate Table in Postgresql
I have the following question in Java: how can I pass to SQL that it should capture the "date and time" of the computer and update the User Table in Postgresql? Follows code: public class…
-
5
votes2
answers348
viewsLimit the database results?
Continuing with the classroom videos, I came across a method of displaying database data a little different, in the video is used: $result = mysqli_query($conn, 'SELECT * FROM comentarios ORDER BY…
-
5
votes1
answer638
viewsfilter records by month
I have the following appointment: $sql= mysql_query("SELECT dia, GROUP_CONCAT(hora) FROM marcacoes WHERE colaborador_id = {$colaborador_id} GROUP BY dia "); Returns the following table: but I want…
-
5
votes2
answers380
viewsHow to transpose the result of a search using SQL Server?
Or better saying how to make the columns of a search result SQL Server, become lines of the result, as follows in the images below: A search result using the clause select whichever: Make the result…
-
5
votes1
answer625
viewsHow to update fields with fields from another table?
I’m not able to update one table with another’s select. I have a table mdl_user which contains several columns and created another users_sg to copy some columns. I copied with INSERT INTO users_sg…
-
5
votes1
answer246
viewsSpring MVC getJdbcTemplate Insert in Oracle return column value
I have a project in Spring MVC, I’m using the getJdbcTemplate to make Insert’s. Only I do not insert the key Primary in Oracle from a sequence and need that value to re-enter another table where…
-
5
votes2
answers1524
viewsCondition on Join or Where?
Is there any difference if I use: select * from a left join b on a.id = b.id and b.id2=1 where ... or select * from a left join b on a.id = b.id where b.id2=1 Sent on: Fri ? The first SQL returned…
-
5
votes0
answers97
viewsDoubt implementation Database SQL
I’m creating a product control for a company, where we need to generate sequential codes for products as they register, sell digital products, so there’s no physical amount. At first I thought about…
-
5
votes1
answer118
viewsFilter using calculated value does not work in Django
I have a model in Django with fields largura and comprimento, and would like to filter it by area: class Projeto(models.Model): largura = models.DecimalField(decimal_places=0, max_digits=4,…
-
5
votes2
answers9742
viewsHow to insert current date in postgresql?
I need to set in a column on postgresql the current date of insertion as the default value for the field. How can I do that?
-
5
votes1
answer2898
viewsCode to show procedures in Mysql
What Mysql code to display procedures created by me?
-
5
votes1
answer95
viewsConcatenate two sql
I have the records: |DT_OBS | DESC_OBS | COD_TURNO | COD_PERIODO| |01.10.16| TESTE 01| 1 | 1 | |01.10.16| TESTE 02| 2 | 1 | |01.10.16| TESTE 03| 1 | 2 | |02.10.16| TESTE 04| 1 | 1 | |02.10.16| TESTE…