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
-
1
votes0
answers206
viewsHow to consult select with two different formats dates in VB.NET?
Talk, you guys! I have dates with two types of different formats in the database, example: MM/dd/yyyy dd/MM/yyyy HH:mm:ss But when doing the query in VB.NET, I did so and it doesn’t work. Public…
-
1
votes1
answer498
viewsHow to make condition in two different tables with sequelize?
How can I make this select in sequelize? select prestadores.status, financeiros.status as prestador_status from prestadores left join financeiros on prestadores.financeiro_id =…
-
1
votes0
answers70
viewsCast for LINQ decimal?
Since there is no Convert.ToDecimal() in language SQL, how could I transcribe a as decimal(18,2) in LINQ? I tried through the decimal.Round() but it’s not working. I have the following query on SQL:…
-
1
votes1
answer375
viewsHow to return the total amount when using OFFSET and FETCH NEXT?
I had to use OFFSET and FETCH NEXT to return a data range between my query. Table CREATE TABLE [dbo].[Usuario] ( [Id] [int] IDENTITY(1,1) NOT NULL, [Email] [nvarchar](max) NULL, [Nome]…
-
1
votes2
answers194
viewsTable values being truncated
I made code in the declaration part of the real number that word balance that it will receive a number with 6 digits and 2 two decimal places after the comma, except that all values that I enter are…
sqlasked 6 years, 7 months ago rafael marques 939 -
1
votes2
answers458
viewsSum in a Pivot Table
I’m learning how to use tables with PIVOT in Sql-Server. I have a table with the item name, seller name and customer id. Item | Customer | ID Rep Pen Set | 1001 | Richard Binder | 25092 | Nick Pen…
-
1
votes1
answer205
viewsError when adding FK
I found just about this type of error in "Select", I followed all the restrictions but it didn’t work! Error from line : 86 on command - alter table tb_consulta add constraint…
-
1
votes3
answers694
viewshow do I make a row_number keeping the document number with different plots?
I would like to know how to create a row_number keeping the numbers of documents equal creating the sequence by parcel. example: doc / cliente / parcela 10 15 1 10 15 2 10 15 3 23 59 1 23 59 2 23 59…
-
1
votes1
answer522
viewsSplit array with multiple INSERT array_push in SQL
I have a foreach that makes the loop in the data of a file, this loop generates some values that are inserted in a array with array_push, I need to break these values inserted in this array to…
-
1
votes1
answer100
viewsQuery 2 SQL tables bring all the results
I’m doing an SQL query to bring users, but I consult 2 tables: users and users_vip No users have all users and users_vip only those who are vip (active or not). When I make my query joining the 2…
-
1
votes1
answer68
viewsIdentify source of database Locks
good morning! On my server, I own Sqlserver 2008R2 Express. I am having lock problems in the database, however, I am not able to identify which process or which application might be causing these…
-
1
votes1
answer43
viewsSelect on condition
I have the following example table (tbl_Local) in Mysql: ID| LOCAL| COR 1 | A |RED 2 | A |RED 3 | B |RED 4 | B |BLACK 5 | B |WHITE 6 | C |RED 7 | D |BLUE 8 | E |BLUE 9 | E |ORANGE 10| E |YELLOW 11|…
-
1
votes1
answer660
viewsHow to sort a date that is in varchar format?
I have the following select: SELECT a.nome, a.cidade, a.telefone, a.dt_criado FROM cadastro AS a GROUP BY a.nome, a.cidade, a.telefone, a.dt_criado HAVING COUNT(*) > 0 ORDER BY a.dt_criado DESC…
-
1
votes1
answer165
viewsDelete with sub-query IN SQL
good morning friends ! I am unable to delete with Count SQL server someone could give a force? Message 116, Level 16, Status 1, Line 32 Only an expression can be specified in the selection list when…
-
1
votes2
answers349
viewsInvert id sequence in a table
I had to migrate a site that was made in pure PHP for Wordpress, searched the internet and managed to copy the data from the table of the old site to the structure of Wordpress, which happened one…
-
1
votes1
answer3608
viewsWhat is the difference between LEFT JOIN and LEFT OUTER JOIN?
What’s the difference between LEFT JOIN and LEFT OUTER JOIN? Can you give me some examples?
-
1
votes1
answer78
viewsHow to select only 1 record per month with SQL
I have a sales chart and would like to select customers' sales, but if the customer made more than one sale per month, I would like you to bring the oldest just, how could I do that? I don’t have an…
-
1
votes2
answers50
viewsSelect only 1 record per month with an aggravating factor that prevents the use of Group By
I have the following table: I need to bring only the oldest customer sale, regardless of the type of sale, however I need the sale guy to come on select, before I had a similar doubt and helped me…
-
1
votes1
answer148
viewsConvert Query SQL Server to Entity Framework
How to convert a SQL of SQL Server for Entity Framework, Ordering field values as follows: of: ({'115-F-G', '10 -H-G ', '98 -T-R'}) for: ('10 -H-G ','98 -T-R','115-F-G') SELECT * FROM ReportePedido…
-
1
votes1
answer43
viewsHow to Take data from an SQL table by referencing only the first position of the VARCHAR type
I need to delete everything that starts with '9' in my seg1 column, for example: If in the table this '954747A' will be eliminated because the 9 is the first position. If you have '34465922A' It…
-
1
votes0
answers80
viewsDownload database data in csv format
I am trying to download the database data in csv format but it is indicating that the SQL syntax is wrong. public void exportarBaseRespostaPI() { String banco = "b2wentregascorreios"; String tabela…
-
1
votes2
answers201
viewsConvert from varchar to float when the string is empty and/or blank
I have a column where the strings are in the following format: "12.05%" I need to do some calculations with these values, and I am formatting the values that are acceptable for the float/double…
-
1
votes0
answers239
viewsHibernate Query with setParameters
Hibernate is ignoring my data from a Map when it is void. If I’m with setParameter("nome",valor) and the value is null it works, does anyone know how to solve? Follow the code: public List…
-
1
votes1
answer38
views -
1
votes1
answer205
viewsDuplicate record in the database
Good evening folks. I am in need of a help to remove some duplicate table records from my Mysql 5.7 database By running the following query I can identify which records are duplicated: SELECT…
-
1
votes1
answer171
viewsTables Displayed in Oracle SQL Developer
Good Night, installed in my notebook the oracle database and the oracle sql: $! I would like to know how to display only the tables I created or create,and not display these others, since it leaves…
-
1
votes2
answers425
viewsI need to relate two tables in order to bring me a result within the conditions I want
I’m using the SQLSERVER Condition(What the result should return to me) Creation of the agenda. Necessary creation of the flow for creation of agenda and blocking to reserve the vacancies; When…
-
1
votes1
answer2740
viewsMaximum SQL date
I have the following table T_PGTOS_ADESAO: Adesão | Tipo Adesão | Data Vencimento Boleto | Data Pgto Boleto 12247 | Cartão | 20-03-2018 | 03-03-2018 38497 | Boleto | 15-05-2018 | 10-05-2018 48289 |…
-
1
votes2
answers705
viewsSQL Error: Can’t reopen table
I have a problem when performing an SQL using a temporary table. I need to bring the data da ultima alteração where the opportunity has been changed. However, this date comes from several tables for…
-
1
votes1
answer426
viewsHow to find an xml tag information using xPath in Postgresql?
I wanted to use the remote xPath, but I’m not sure how it works. I have a table and inside it a column that stores XML's. I would like to conduct a consultation that brings the value that is within…
-
1
votes1
answer217
viewsHow to insert a row in the sql table when clicking the button?
I have an immovable site that I am implementing the option of favorites. When opening the property and clicking favorite, it should insert in a new row in the favorite table, this one below (status…
-
1
votes1
answer298
viewsHow to return the sequence of the week in the reported period?
Good morning, I need to return the sequence of the week of the month (of the reported period) in two fields, initial and final date. In PHP and MySQL. Currently returns the week number in the year,…
-
1
votes4
answers949
viewsDay and month comparison on SQL Server
I need to filter a query of every client who has a birthday between two informed dates. How can I make a comparison of dates disregarding the year registered with the client? The current…
-
1
votes1
answer54
viewsdoubt sql database
i want to enter record in DS_ITEM and the mistake you give me is "Cannot insert explicit value for identity column in table 'SCD_ITEM_CONTR' when IDENTITY_INSERT is set to OFF". How can I make this…
-
1
votes2
answers43
viewsSearch for missing records within the same table
I have a table containing user information. it contains a field called competence. And when I want to pull information from some user I pull competence so: SELECT * FROM registro WHERE competencia =…
-
1
votes0
answers43
viewsUpdate Error Oledb C#
I cannot use the UPDATE command more than once. (https://drive.google.com/file/d/1xyqp6rA4Rk3AvneFaUlqk6AVvjQjbtSi/view?usp=drivesdk)…
-
1
votes1
answer608
viewsCalculation between Rows and Columns Different SQL SERVER
I need a solution or function to perform the following calculation (Backlog(dia anterior) + Abertos(dia atual)) - fechados(dia atual) = backlog(dia atual) Here’s a screenshot of the table below.…
-
1
votes1
answer35
viewsreturn only to your last move of each code
A table records the movement of items by item code, date and time of movement. So the presentation is as follows: CD_Item | DT_Mov 15 10/04/2018 08:52:36 15 21/05/2018 09:32:10 15 20/05/2018…
sqlasked 6 years, 6 months ago Robson Junior 79 -
1
votes1
answer65
viewsMvc List only available rooms and not busy ones
I have the following problem: A reservation has associated with you a client and a room. When creating a reservation, I have to fill in some fields (such as customer name, date of arrival, date of…
-
1
votes1
answer174
viewsIs it possible to identify the source database of a stored SQL database?
I have a stored-Procedure in SQL 'spr_insere_carga_requested' where when executing the sp_helptext command in a given database it was not identified; there is some way to identify the database where…
-
1
votes1
answer105
viewsHow do you use the UPDATE command more than once?
I cannot use the UPDATE command more than once. For example, when I do the update on id 43, sure. But when I try to finish 44, it does not finish, but 43 that gets the update.. Code: Int att,index;…
-
1
votes2
answers100
viewsRemaining minutes between field and dateAtual
I am trying to create a direct query in mysql where I must return some value if the time interval of the current date and my datareg field is 02 minutes. SELECT * FROM tabelax WHERE grade = 19 AND…
-
1
votes2
answers1533
viewsHow to select data from a column as columns in SQL?
It is possible to make a query (SELECT) of data returned from a column such as columns? select questores from table; | coluna | → coluna |-------------| | dado1 | → dados retornados da consulta |…
sqlasked 6 years, 6 months ago Brendow Adriel 29 -
1
votes1
answer245
viewsMysql comparing a number with string returns true if the string starts with the number
I have the following table in the database: idUser - Username - Group 1 - John - 5GR 2 - Donate - 1GR And the following query: SELECT * FROM `table` WHERE `idUser` = '$name' OR `Group = '$name'…
-
1
votes3
answers393
viewsGet last ID or date inserted in a Mysql table
I have a history of conversations that are recorded in the table sql "conversation" and I want to pick up who was the last person who inserted a message in the conversation to know if it was the…
-
1
votes2
answers494
viewsSQL Left Join - shorter date longer than current date
3 tables: Processo, Evento, Alerta The goal is to make a query that returns all processes by adding the columns of the most recent event type and date MAX(DataEvento) and the next warning (shorter…
-
1
votes1
answer1454
viewsDifference between EXISTS and IN in postgres?
I have a doubt that I have already researched here, but for me it made no sense the explanations. I have this query: SELECT * FROM a WHERE id IN (SELECT ID2 FROM b) And this: SELECT * FROM a WHERE…
-
1
votes0
answers70
viewsCheck empty mysql column
I’m having trouble checking which columns are empty on mysql. I’m using the COALESCE but it only checks the first column of the sequence: COALESCE(column1, column2, column3...) AS values If column1…
-
1
votes1
answer113
views -
1
votes0
answers48
viewsQuery to return followers of friends
I’m starting in SQL and I’m having trouble making a query with multiple lines returned. I’m creating a generic twitter clone. Goal: Return users who are followed by the people who logged user…