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
-
0
votes1
answer361
viewsTrigger to fill table with data from another table
I want to fill a table with the data being placed in another. CREATE TRIGGER `trg_jogo`AFTER INSERT ON `tabela1` AS INSERT INTO `tabela2` SELECT * FROM `tabela1`; I cannot do the process to copy the…
-
0
votes3
answers1128
viewsOracle - Select distinct in one column only
I have a table: aluno1 - data 1 student 1 - date2 student 2 - date1 student 2 - date2 And I want my query to return: aluno1 - date1 (date + recent) aluno2 - date2 (date + recent) How do I give a…
-
0
votes2
answers184
viewsHow to automatically name a manually created CONSTRAINT in Sqlserver 2016
Hello, I am creating a database and need to create some compound Index to optimize the bank processing. The problem is that I don’t want to have to name these Indexes one-on-one. Normally, I create…
-
0
votes1
answer22
viewsCompare id in two tables and return sql promo value
Hello! In my product table and in the promotion table are idcategory, I have my product with a certain category and when I find the same idcategory in the promotion table and this is with active…
-
0
votes0
answers32
viewsHow to save the path of an image when creating a table in SQL?
Hey, guys, what’s up? I have this case: I need to create a product table with the attributes 'id', 'Description', 'stock', 'unit', 'price' and 'local_photo', only I have doubts about the type of…
-
0
votes1
answer33
viewsQuery Transformation
Does anyone know if it is possible to transfer a SQL SERVER query into a new table? No longer query to be shown with a "show table" command made from a query for example ?
-
0
votes2
answers389
viewsSum the value of the column by grouping monthly and by product
Staff I need to calculate the monthly consumption of the licenses used here in the company I work. I have a table with the product (dbo. Product), the number of licenses installed on the server…
-
0
votes0
answers83
viewsInitial SQL to list clients (PF and PJ). How to migrate a pure SQL Query to Laravel Eloquent?
I set up an initial SQL to pull the data. It’s working in pure SQL. I need to migrate this code to Laravel’s eloquent pattern. Can anyone help me? Thank you! Follow the example SQL: Code: SELECT…
-
0
votes1
answer58
viewsid PRIMARY KEY, AUTO_INCREMENT starting from 1
I’m having a doubt, a stupid problem. Before to carry out this code: CREATE TABLE tabela ( id int AUTO_INCREMENT, title varchar(50), descricao varchar(100), PRIMARY KEY (id) ); when putting the…
-
0
votes1
answer76
viewsSQL Plus - Export CSV without Query in File
I am trying to export the result of a query in SQL PLUS to a CSV. It is working, but I want used for extraction is coming in the first lines of the CSV file, which hinders the end user. Have some…
-
0
votes0
answers45
viewsFinding search results in custom fields
How does Wordpress search in custom fields? I researched and saw that his search works using the title and content of the content. I created a project that uses custom fields, such as: address and…
-
0
votes3
answers190
viewsCONNECT BY application - SQL Oracle - DFS search without repeating lines
Dear Members, Suppose a graph is registered in two ways: TABELA_A: T | V1 | V2 1 | 1 | 2 2 | 2 | 3 3 | 2 | 4 4 | 4 | 5 TABELA_B: T | V1 | V2 1 | 1 | 2 2 | 2 | 3 3 | 4 | 2 <====OBSERVEM QUE AQUI…
sqlasked 6 years, 2 months ago Davi Mantovani Ricci 1 -
0
votes1
answer23
viewsAND no SQL (Firebird)
I have the following code: UPDATE PRODUTOS SET categoria = '001' WHERE marca = '1774' But there are over 400 brands.. I thought about using AND in Where to do it with multiple brands at once, but it…
-
0
votes0
answers26
viewsAzure Data Studio - How to shortcut to open procedures?
Fala galera, I am using Azure Data Studio and I know that there is a shortcut (F12) to open a Procedure, the problem is that when I open this shortcut, the existing file opens with the CREATE…
-
0
votes1
answer269
viewsHow to convert Datetime to timestamp? (SQL SERVER)
Today I have the following situation, I need to send the current date and time of the request in an int format, as image below Below are some attempts I made, but when testing the conversion to date…
-
0
votes0
answers21
viewsHow to verify and manipulate native LOG in Sqlserver?
I am working in an application generating a Batch service being developed in T-SQL. Just like Mysql and Postgresql have their LOG files, where are these LOG files in Sqlserver? Another question is…
-
0
votes1
answer31
viewsHow to delete rows in three tables with specific condition (SQL)
Hello. I need to delete the contents of a select that collects rows of three tables, which has columns with common values but which are based on parameters of a single table to exclude. select *…
-
0
votes0
answers32
viewsI am trying to copy the column fields from one table to another already created work, however, I am getting this error
UPDATE variaveis_copy SET descricao = ( SELECT descricao FROM variaveis WHERE variaveis.variavel = variaveis_copy.variavel ) (ERROR: more than one Row returned by a subquery used as an Expression)…
-
0
votes2
answers115
viewsSelect all customers and check if you are carrier and supplier
I want to make a select that selects all customers and next create two columns a carrier call and another supplier and in each of them mark yes or no. Ex: Código Nome Fornecedor Transportadora 01…
-
0
votes2
answers40
viewsUsing formula in SQL
Hello, I’m having a doubt and I can not find examples to progress, following: select 'disponivel' as TIPO , COUNT(distinct dp.ds_nome) as qtd FROM dm_pessoa_treino dp union ALL select 'em_uso' as…
-
0
votes1
answer49
viewsSQL - How to bring only rows (ID and Date/time) with less than 1 hour
I need the following help: I have a table that I need to compare the transactions with the same ID, but only bring those ID lines that have the previous transaction with the same ID with less than…
-
0
votes0
answers28
viewsHow to use PDO and PHP to Show in Table Query Data
I have a question. I do not understand why my code is not correct. Please, if you can review it, I would be very happy. <?php require_once "db_connect.php"; //conectar banco $conectar = new…
-
0
votes0
answers62
viewsHow to import a . csv file to a Stored Procedure on SQL Server without using "BULK INSERT"?
I am trying to perform an SP that lists the . csv files in a folder via the command XP_CMDSHELL And then imports the files. csv for an auxiliary table in the database, but I do not have permission…
-
0
votes0
answers17
viewsPASS SQL FORMULA IN ACCESS (TEXT MINING)
Good afternoon! I’m passing a sql formula for access WHEN ((SA_P1_RESULT_VISITA LIKE '%VISITAD%') OR (SA_P1_RESULT_VISITA LIKE '%FACHAD%') OR (SA_P1_RESULT_VISITA LIKE '%INSTALA%') OR…
-
0
votes0
answers28
viewsI want to make a select in my database to see all the results that are: status = 1
$sql = "SELECT * FROM pagamentos WHERE status = 0"; while($aux = mysql_fetch_row($sql)) { echo '<td>'. $aux['nome_cliente'] .'</td>'; } …
-
0
votes1
answer65
viewsChange the number of decimals in the table structure (SQL SERVER)
Good Evening Everyone, I have 3 fields in a table that use the "Data type" defined as "decimal(15, 2)" and I need to change (via code) to "decimal(15, 3)". That is, change from 2 decimal places to…
-
0
votes1
answer32
viewsHow do I convert a date into varchar?
How do I convert a date into varchar? I tried to convert to normal mode but couldn’t, could anyone help me? I want DT_PAGAMENTO to be in "03/02/2021" format, in dynamic mode. SELECT NUMERO =…
-
0
votes0
answers112
viewsHow to update a <select> with data from another <select>
I would like to know how to update a select with data from another. I currently use SQL, I already have a connection created: $connection = new COM("ADODB.Connection"); //instancia a classe de…
-
0
votes1
answer20
viewsSeparate database tables to obtain values separately
I have a table with values every month of several years, I would like to separate each year with the respective index calculation for another table or make the queries in this same table, as I would…
sqlasked 3 years, 9 months ago Breno Nahuz 97 -
0
votes1
answer120
viewsSUBSELECT WITH COUNT(*) SQL
SELECT CPF FROM ZPCF WHERE CPF IN (SELECT TELEFONE, COUNT(*) FROM ZCPF WHERE GROUP BY TELEFONE HAVING COUNT(*) > 1) I need you to bring Cpf along with phone numbers, there are phones registered…
-
0
votes0
answers329
viewsStrange characters being inserted into the Oracle Insert
I have an oracle XE database, I want to import sql scripts to fill the tables, however, characters with accent and Ç for example get strange characters for example. In this example Index: Insert…
-
0
votes0
answers23
viewsSelect in dynamic XML returning all possible values within the tags - SQL SERVER
i wonder if it is possible to select in an XML bringing all possible results within select and stored in a variable XML: <Nome>@PartyId</Nome><Nome>@CallId</Nome> The tag…
-
0
votes0
answers35
viewsCREATE TABLE with derived column Postgressql
Greetings to everyone, I am learning SQL recently and I found myself with this problem inside a database that brought from the internet to do some exercises, but I’m encountering an expression error…
-
0
votes1
answer136
viewsupdate nls_database_parameters Oracle
I need to change the parameters nls Oracle, placing the image characteristics below: I’ve tried a lot of tips, but you always say I have insufficient privileges. These are my settings: NLS_LANGUAGE…
-
0
votes2
answers40
viewsSelect in two tables with Count
I have two tables in Mysql clientes id nome cat categorias id nome I need to create a SELECT, that shows all categories, but only categories that have more than 10 clients (for example). I wanted it…
-
0
votes1
answer111
viewsrelate two tables
I would like to know how to relate two tables in different databases so that every time the value in the bank table1.dbo.table id1 will be changed also in the bank.dbo.table id1, modifying according…
-
0
votes1
answer29
viewsI need to show you the details of the customer who bought the most
This query is giving error: select c.* from carrinho_de_compras as cc inner join clientes as c on c.codigo = cc.cod_cliente inner join produtos as p on p.codigo = cc.cod_produto where (select…
-
0
votes1
answer20
viewsSQL to group records
I made the query below to load the records with the highest date of exit (a same record may have several dates): SELECT RA, MAX(Data_Out) AS Data_Saida, Placa FROM dbo.RA_Vehicles GROUP BY RA, Placa…
-
0
votes1
answer56
viewsView most current sql server 2008 record
I am trying to get the only last record (last sale) of each customer and I am not succeeding. I tried several ways, but nothing.. Only returns all sales from the date. Follow my query. I appreciate…
-
0
votes1
answer125
viewsError inserting data into recordset with oraOLEDB
Good afternoon, everyone. I have a problem in various applications here in the company that are in VB6. When I try to include a record in a recordset an error occurs (it is described in the code),…
-
0
votes2
answers42
viewssum of values of more than one table
I have a problem in the code below. When I put to add the field valor table lnota, it brings a wrong result of the account; if I leave only the field, it brings the right value SELECT…
sqlasked 3 years, 7 months ago Rodrigo Costa 1 -
0
votes0
answers65
viewsChange the order of an XML tag via T-SQL
Hello! I’m on a demand where for a certain reason, XML was generated with the order of the exchanged tags... :( Scenario: I have a column in the SQL Server database (as of 2008) that contains NF-e…
-
0
votes0
answers13
viewsUser Access Control by Pespectiva
I set up a Cube on the Analysis Server and created several pespectives from it. The idea is that users consume the data from these. It turns out that I wish a given user could only see a single…
-
0
votes1
answer38
viewsfilter between two dates with Join
I have two tables: col (collaborator) and Indicacao. I made a select to know how many referrals each employee has. It’s working but I can’t filter by date using between. SELECT c.id, c.nome, funcao,…
-
0
votes0
answers54
viewsParallel Task How to improve the performance of this function
I would like a suggestion to improve the performance of these methods. They have taken too long to complete. Please if the question is not very clear just say that I try to improve I will provide…
-
0
votes0
answers16
viewsInsert + sign into a table field with PHP
Follow the SQL command of the Insert that I need to insert in the table, the database is Postgres. '''INSERT INTO pneu_templates (ds_template, cd_brand, cd_usercadastro) VALUES (UPPER('test+'), 86,…
-
0
votes1
answer544
viewsSubquery in Oracle SQL
I have a code that aims to return open invoices from a customer in a specific period of time. But I want to add a field that shows the total number of invoices, regardless of the debt period. The…
-
0
votes1
answer45
viewsError while searching for date greater than 1 year DATADIFF() and DATAADD() function
Hello I need to perform a select in a database where the dataCompra is longer than one year. But I need to use a clause in my Where and when I try to use the function DATEDIFF() and DATEADD() so it…
-
0
votes1
answer87
views"ORA-00955: name is already used by an existing Object" error
When I try to run this part of my code in Oracle Live SQL, it gives the error "name already assigned to existing object". But there are no repeated names here, other than my primary and foreign…
-
0
votes1
answer259
viewsHow to create a Function that calculates CRC16 in SQL Server?
can tell me if there is any sql function that calculates CRC16, the calculation method is listed as "CRC-CCITT (0xFFFF)". CRC-CCITT (0xFFFF) -> polynomial: x 16 + x 12 + x 5 + 1 I tried to create…