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
answer35
viewsConsult the most duplicated record
I have a problem to recover the teacher who teaches more subjects in this table, in which case I want to recover the code that has more duplicated records in the cod_prof column. create table…
-
2
votes1
answer57
viewsReturn fields from parameters
Good night, I need the return of a SELECT to be dependent on the parameter passed in SELECT Example declare @variavel nvarchar(50) Select peasant, campob, campoc, campod, peasant, from table I need…
-
2
votes2
answers706
viewsInform a date, and catch the interval of the week of the month of that date (from Sunday to Saturday)
I am in need of an SQL command (Sqlite for android), which returns the interval of one week (from Sunday to Saturday) of an informed date. For example: inform the date '05-05-2016', hence the sql…
-
2
votes2
answers19181
viewsHow to check if a table exists in the SQL Server 2005 database and if it does not exist create it and the columns
How to check if a table exists in the SQL Server 2005 database and if it does not exist create it and the columns. The purpose of this process is to create this routine for when I need to create a…
-
2
votes0
answers198
viewsMysql Workbench 6.3 does not change the data type of the attribute in the table, it always goes back to the previous one
Does anyone use the Mysql Workbench Designer tool in version 6.3 ? I’m having a hard time changing a data type from a certain attribute, whenever I change and enter it back to the previous…
-
2
votes1
answer78
viewsJava - How to validate user group in SQL and Save result?
Good morning, I have the following code in Java Desktop. I wanted to know how I can capture this user’s group and save it into a variable. Since when it returns the value and stores in the variable…
-
2
votes1
answer2076
viewsHow to set a Primary key to an existing table on Oracle?
I usually do it directly from the IDE (Sql Developer), but I need to run the script this time. Assuming the existing table TB_CR_INDICADOR_PERIODO and the column COD_CR_INDICADOR_PERIODO as the…
-
2
votes2
answers91
viewsQuery mix of oracle products
I made an indicator here in the company where I list product information, quantity sold, average value, etc. That in a period of time. Now I need the following information: Which is the product that…
-
2
votes1
answer48
viewsProblem with clause IN
I need to use the IN clause in a situation where the in part is a string. Example: SELECT * FROM BLABLABLA WHERE 4 IN ('6,5,4') It causes me this mistake: Conversion failed when converting the…
-
2
votes1
answer34
viewsDifficulty with PDO
I’m starting with the use of PDO and I have a doubt that I could not solve. I do the select below that will return me 2 hours: $sqlSaida = 'SELECT horario FROM HORARIOS WHERE COD = :codsaida UNION…
-
2
votes1
answer2135
viewsNULL error when adding a new line
Good guys, I have a bench as described in the image below: I have some questions: A) Uma geladeira da marca Brastemp 220 V que custa R$ 700. B) Três cadeiras de madeira em cores diferentes, cada uma…
-
2
votes2
answers145
viewsModeling Database
Specifying the tables I’m doubtful are, in my case, a work of a company for the college, the tables: Input and Diagnosis, in which the input is when someone brings some equipment, and then is made…
-
2
votes5
answers1793
views -
2
votes1
answer345
viewsUsing multiple group by in a query
I have 3 tables: Products, Orders and Order Item. Table: Produtos id_produto foto_produto categoria sub_categoria --------------------------------------------------------- 0081 15487.jpg 4 32 0491…
-
2
votes2
answers754
viewsHow to change the last 100 table records in the Postgresql database?
I need to change a table field in my database to perform some tests, and would like to update only the last 100 table records. I’ve tried that code: UPDATE titulo SET autorizado='S' ORDER BY…
-
2
votes1
answer87
viewsConvert SQL script to Linq
I need to convert the SQL script below to Linq. SELECT [ID_Pessoa], [ID_ArquivoPagamento], SUM([Peculio_Valor]) AS 'Peculio_Valor' FROM [VW_PESSOA] WHERE [ID_Pessoa] = @ID_Pessoa AND…
-
2
votes3
answers756
viewsHow to group results in a row?
I would like to perform a query About the table FICHA_EXAME with the following data: CREATE TABLE FICHA_EXAME ( FICHA smallint, EXAME VARCHAR(15) ); INSERT INTO FICHA_EXAME VALUES (1,'Hemograma');…
-
2
votes1
answer63
viewsError in SQL statement
I have the following comic: When I run the following Query: SELECT tbCelula.* FROM (((tbTiposMonitorizacao INNER JOIN tbMonitorizacaoProj ON tbTiposMonitorizacao.TM_ID = tbMonitorizacaoProj.MP_T_ID)…
-
2
votes2
answers405
viewsNOT EXISTS in update?
I have the following SQL: insert into teste (id,nome) select 2,'João' from dual where not exists(select * from teste where nome = 'João') Would you like to do the same with update? Is there any way?…
-
2
votes2
answers676
viewsQuery does not sort records by Asc/Desc
I have a table called cadcha (registration of call) in the database where all calls made by employees of a particular company are stored. cadcha --------------------------------------------------…
-
2
votes2
answers48
viewsCheck in a table if a user is not registered
Colleagues, I have a table called salas_usuarios, this table contains all users registered in the rooms and another table called users, where I store users. But I would like to check which users are…
-
2
votes1
answer1010
viewsPostgresql syntax error using keys
I’m having trouble understanding why pgadmin is pointing syntax error in my query. select first_name, coalesce(to_char(avg(p.amount),'99.99'), 'nnn') valor_medio from { select c.first_name as…
-
2
votes2
answers977
viewsConnection to the database in ASP.NET with Entityframework
I need to migrate a system from one server to another. The system is in ASP.NET and the connection to the database is a little strange. I need to know how to connect to the database. The only thing…
-
2
votes1
answer590
viewsField alias in oracle Where clause
I have a Decode in my select so: ..... DECODE(MAT.IND_TIPO_MAT_MED, '1', 'BRASINDICE', '2', 'SIMPRO', '9', 'TABELAPROPRIA') TIPOTABELA, ..... I need to pass these values on the clause where, for…
-
2
votes1
answer296
viewsContent migration between different post types in Wordpress
Good morning, I am currently working with a project for a news portal that is the grouping of 4 different companies, but one of these companies will cease to exist and all its posts will be…
mysql sql wordpress phpmyadmin wordpress-pluginasked 8 years, 10 months ago Lucas Bernieri Ramos 143 -
2
votes0
answers201
viewsTurn Column into "Pivot" row
I’m trying to turn the column "prtnum" branded yellow in Line, I’m trying to use the PIVOT but I’m not succeeding I’ve tried some ways and not right: Select Distinct (ORD_LINE.ordnum),…
sqlasked 8 years, 4 months ago Ariel Gonçalves 81 -
2
votes1
answer858
viewsProblem inserting records into Oracle
I’m having trouble entering records in Oracle, below follows the insert that I use: insert into COMPRAS (id, valor, data, observacoes, recebido) values (id_seq.nextval, 200, '19-FEB-2008', 'MATERIAL…
-
2
votes1
answer66
viewsSelect dates based on the total sum of a given column
Good night. Based on the example registration attached, I would have to select all dates that are equal and are in the same restaurant and the sum of the amount is > 10, because I need to disable…
-
2
votes0
answers230
viewsEfficient search with phrase and keywords
I am using the following syntax in SQL for searches: SELECT * FROM exemplo WHERE MATCH(title,content,tag) AGAINST(?) Regarding the LIKE I had a better result, but it is not yet 100%. for testing…
-
2
votes2
answers5400
viewsMysql not connecting connects by socket error
Good afternoon friends, after having correctly installed Mysql 5.7 on my Ubuntu 16.04, while trying to connect to the bank, I get an error message saying that I could not connect through the socket.…
-
2
votes2
answers497
viewsHow to concatenate two Data?
How to concatenate two dates of the type DateTime, one of which may have its value equal to NULL, I’m trying this way; DECLARE @DATA1 DATETIME = GETDATE(), @DATA2 DATETIME select…
-
2
votes2
answers3542
viewsCompare with earlier date in oracle
Hello, I need to check which purchases were made in the last 7 days select * from carros car where to_date(to_char(to_date(car.datacompra,'yyyymmdd'),'dd-mm-yyyy')) = trunc(sysdate - 7) returns me…
-
2
votes1
answer656
viewsUsing last_insert_id(), is it credivel if several users enter at the same time in the database?
I have a doubt about the method last_insert_id() mysql. And the following: I am creating a procedure to insert into 3 tables, example: person (idPessoa, surname,) employee(idEmployment,idPessoa,)…
-
2
votes1
answer57
viewsDifference between List and and Return in Entity
Hello, I am with a doubt when I will take the data of an SQL query, there is the possibility to pull by list and by Entity, which is would be the "most correct" or the usability of each? public…
-
2
votes1
answer346
viewsNumber of lines increases after use of JOIN
Hello, I’m new to SQL and I’m having a doubt. As in the example below, I wanted to take from a table 'b' the description of the code present in table 'a'. But the number of rows in table 'a' when I…
-
2
votes2
answers8408
viewsHow to concatenate the results of a RELATION into a SELECT?
Having the tables PRODUTO , CATEGORIA whereas a CATEGORY may have several PRODUCTS, would like a select list in a column nvarchar all the PRODUCT NAME of a CATEGORY. Something like: select concat(…
-
2
votes1
answer203
viewsIndexes in primary key columns
I know that each case is a case, and that there are no ready-made rules on the creation of indexes. In my case, considering that the primary key of each table of my bank is used in wheres of my bank…
-
2
votes1
answer920
viewsSUM and GROUP BY doubling values
While trying to add and group values, I found that the SUM and GROUP BY are not behaving the way I hope and could not identify the cause. Making the query below SELECT…
-
2
votes1
answer705
viewsHow to join the two tables in this case?
I have two tables a "students" with the enrollment and enrollment and another "faz_teste" with the grades of the students in certain tests. I used the pivot command in the table "faz_teste" to…
-
2
votes1
answer140
viewsSwap rows for columns
Hi, I have the following query: set NOCOUNT on; declare @_mes int = 2 declare @_ano int = 2016 declare @_dataini datetime = CONVERT(DATETIME, '01/' + REPLICATE('0', 2 - LEN(@_MES)) + CAST(@_MES AS…
-
2
votes4
answers3541
viewsHow to bring records of a LEFT JOIN even if not obeying the WHERE?
Exemplifying, I have the tabela_A: cod nome 1 stack 2 overflow 3 stackoverflow and tabela_B: cod_tabela_A ano mes valor 1 2016 1 100 1 2016 2 115 2 2016 1 90 When made a LEFT JOIN, returns me the…
-
2
votes3
answers3385
views2 COUNT within a SELECT with LEFT JOIN
I have two tables: users: id | nome | email shipments: id | id_envia | id_recebe Every time a user sends a card (which goes by email) to another user, mark this table, and every time they receive…
-
2
votes1
answer153
viewsShowing Results other than a column
I have a table CAIXA, where in the column TIPO can have two results, the 00 and the 99, where 00 is the opening of the terminal and 99 the closing. I’m trying to create a query where the result is…
-
2
votes2
answers574
viewsPostgresql query without data return
See the following SQL code: SELECT * FROM venda ve WHERE ve.datavenda <= DATE '28/08/2016' In the database you have the following data: The above SQL query is not returning any results, why?…
-
2
votes1
answer102
viewsSelect Query with AJAX and PHP
I am developing a php system and have a page where it lists several results of a SELECT, so far so good... and I have a input text where I would like every letter I typed into it, the results to be…
-
2
votes1
answer87
viewsWhere are the databases saved in SQL*Plus?
I downloaded SQL*Plus on the Oracle website, installed (my notebook is Windows 10) created user and already created some banks, but do not know where it saves the banks I created. Where is?
-
2
votes2
answers2146
viewsIs it possible to connect a C-based application to a database?
We usually use files to save data using language C (at least). It is possible to connect a relational database to any application made in C? If yes, do you need a library for this and how is this…
-
2
votes0
answers434
viewsHow to Create 15 minute SQL Interval?
I have a field timestamp and I need to create an interval every 15 minutes. How in Sql I should do this ? Data = YYYY/MM/DD HH:MM:SS The purpose is an analysis where I need the amount of products…
-
2
votes2
answers1443
viewsORA-22922: nonexistent LOB value in SELECT
I am facing a problem with two different consultations on oracle. Both have the sql snippet REPLACE(dbms_lob.substr(wm_concat(disctinct <COLUNA>)), ',', ', ') The error that returns is the…
-
2
votes1
answer548
viewsSql Server Error: is not a recognized Function name
I have two functions in sql server that are not being recognized by the database -- Não loga conexões de usuários de sistema IF (ORIGINAL_LOGIN() IN ('sa', 'AUTORIDADE NT\SISTEMA', 'NT…