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
votes3
answers1241
viewsAdd a column with row number in select result
How can I add the row number of the select result in an additional column? For example: select e.ds_estados from estados e This select would return me the registered states AC AL AM ... TO I would…
-
2
votes1
answer501
viewsHow to pick up data after a 2 string separators in a select (SQL)?
I have a string where I store day, month and year, no field is required, and I separate the fields by a pipe |. If the user put only the day via staying "25", if put the day and the month or only…
sqlasked 8 years, 3 months ago daniel12345smith 2,120 -
2
votes3
answers849
viewsHow to go through each row of the database compare and update a specific column?
I have a table called PRODUCT and I need to make a comparison between two columns, the column DATA_INICIAL AND DATA_FINAL, for each row travelled, if the product is not in agreement should enter the…
-
2
votes2
answers4251
viewsHow to make a percentage calculation on Oracle?
I can’t make a Select that can perform 1 ICI calculation on Oracle. Table VS01 Campos: PD = 001 TP = 100 reais ICI = 15 Select PD,TP,IPI, TP * IPI% AS TOTAL <<< aqui que não consigo…
-
2
votes1
answer899
viewsError opening Sqlconnection
The following I have a gridviewer that is connected to a Query with a Table called Server Table. I want to add some things to the columns gives the following error Instance failure. In this part of…
-
2
votes1
answer421
viewsFEED TABLES (SQL SERVER )
Opa Bom dia. I have a sql database, in this database there is a table for People, it is a second table for registration of credentials, in a third table and made the association of the credential…
sqlasked 8 years, 3 months ago Gustavo Braga 31 -
2
votes1
answer971
viewsSQL date filter on timestamp
I have the following query: SELECT name, commission, timestamp, state_name FROM magry_awoaffiliate_commission c INNER JOIN magry_users u ON (c.user_id = u.id) INNER JOIN magry_virtuemart_userinfos v…
-
2
votes0
answers51
viewsOpening Sqlite3 in Windows10
When I open Sqlite3 on Windows 10, it simply opens the command prompt, giving command permission in front of the line sqlite>. Already in windows 7 and 8 it opens normally. My intention to use…
-
2
votes1
answer148
viewsDevelopment without EF ORM
It is valid the development without ORM, because today I want to develop an ERP, but I have no knowledge in any framework, is it valid I do everything in hand? I will have the same result? Because I…
-
2
votes1
answer1013
viewsHow to do date search through dateTimePicker?
How to search through a dateTimePicker (with Valuechanged event) dates entered in a Data Grid View? When I press the year I want all the records for that year to appear, then press the month and all…
-
2
votes1
answer90
viewsDoubt to bring mysql data
I have the following question. Consider that I have the following sales data: Two former states: São Paulo (Atibaia, São Paulo and Campinas) and Paraná (Londrina, Curitiba, Cascavel). | cidade |…
-
2
votes1
answer48
viewsOnly spend a year in a proc of sql server 2014
I made a filter in a PROC of my own and I’m not getting any results. Running proc did not give any error, but it does not bring any result and I do not know if it is correct. The colleague said I…
-
2
votes1
answer763
viewsInsert with two different selects
That one of mine insert is not working. insert into t_cmo_oit1980 (id_oit, id_exm_rea) select max(id_oit) + 1 from t_cmo_oit1980, select id_exm_rea from t_cmo_Exame_Realizado where id_exm = 3936 and…
-
2
votes1
answer108
viewsRemove a Foreign key from a production server?
I have a table cad_address with the registration of the address of my users. I also have another order table mov_order that has a key Foreign address_id to the address table, responsible for the…
-
2
votes1
answer38
viewsError when grouping table field
I need to group the data of a SELECT across the countryside a.afo_vch_NmrCtf, because the data is being returned as follows: When I use the GROUP BY the following error is returned : Msg 8120, Level…
-
2
votes1
answer236
viewsDebug Proc in sql server 2014 database
I use Sql Server 2014. I am having problems with Stored Procedure, because when running with certain filters, it triggers this error: Message 512, Level 16, Status 1, Procedure…
-
2
votes1
answer255
viewsAdd the same column by different criteria?
I’m trying to create a report using ReportViewer that makes a SUM in the same column for different criteria. My query works well in Phpmyadmin but in Querybuilder of Reportviewer does not work and…
-
2
votes2
answers511
viewsProtect SQL Server Database
I have 2 SQL Server databases in my SQL Server Management Studio. I would like to put password in one of the two, making it impossible to access it, is possible?
-
2
votes2
answers1598
viewsHow do Postgres create a file to populate a bank?
I have a database in POSTGRESQL populated , I wanted to know if there is a command SQL that returns an aqruivo that had the following command for all existing tables: INSERT INTO aluno(id , nome,…
-
2
votes1
answer65
viewsInsert Sql Server
I have a multi-column table. The unique identifier is the ID, but my question is the following: I have a column version, I want to insert only a value without repetition. How can I implement this?…
sqlasked 7 years, 6 months ago Ana Carvalho 389 -
2
votes2
answers1770
viewsHow to force a drop table into SQL?
While trying to give a drop table in a table that has relationships, the following error occurs: #1451 - Não pode apagar uma linha pai: uma restrição de chave estrangeira falhou Is there any way to…
-
2
votes1
answer290
viewsMYSQL to POSTGRESQL via SED
I am looking for a way to migrate my backup from a Mysql database to Postgresql. The simplest way I found was using sed upon backup, but it hasn’t worked. It was like this: 1 - performing a backup 2…
-
2
votes2
answers2067
viewsOrder change of Sql columns?
Good morning Could you instruct me to change the order of the columns in a table? Example: I have the Table IcmsMvaUF in the following order: I’d like to pass the column MvaEmpresa to come first, to…
-
2
votes1
answer1016
viewsView with parameters without external Where?
I need to receive parameters for a view, but how she got the COUNT(DISTINCT DTA_HOR) I can’t with the where external. Would it have some other way? SELECT EX1 ,EX2, EX3, EX4, (SELECT COUNT(DISTINCT…
-
2
votes1
answer117
viewsSQL doubt with COUNT
Hello, I have a query as below, and I have some questions regarding COUNT, would like help to understand and solve the problem : public String getQueryPrincipal(String queryPrincipal) { return…
-
2
votes2
answers441
viewsSystem.Data.Sqlclient.Sqlexception: Conversion failed when Converting the varchar value to int
I’m getting this Exception in c# when I try to read SQL data. I’m wondering if this error is a problem with my SQL or C#. My SQL code that makes the conversion is this: `$ (SELECT ORDEM FROM TABELA…
-
2
votes1
answer337
viewsCount rows that have the same value in 2 different columns?
Table ID jogada pontos 1 1 3 1 1 1 2 5 1 2 5 1 2 5 3 2 5 3 I wanted to create a query that COUNTS the playing lines and ADDS the total of points, but that indicates the sum by repeating the "ID"…
-
2
votes2
answers1894
viewsCreate total sales (value) per customer (SQL)
I need to make a procedure to install the column cli_TotalCompras of the customer table with the total (in value) of the customer’s purchases. On the table vendaProduto have the value…
-
2
votes3
answers8342
viewsSELECT in a table using NOT EXISTS SQL (SERVER 2012)
I’m trying to make a select tb1 using Where NOT EXISTS (select* tb2) I am trying to select the line in tb1 that does not exist in tb2 to perform an INSERT later. But when testing in select it is not…
-
2
votes1
answer55
viewsSQL in DB Mysql
I have the following situation, a register with 5 fields being them: Type1, Type2, Type3, Type4 and value The 4 type fields are combos fields, where you can select the all option, or any other…
-
2
votes1
answer567
viewsSQL SERVER EXPRESS 2014 ERROR (Microsoft SQL Server, error 1225)
Good morning, all right guys? Following work with database, and we are having some problems with SQL SERVER 2014 x64, on Windows 10. I am doing the installation normally and changing the network…
-
2
votes2
answers212
viewsError in Trigger
I am making a system that deals with monitoring cattle and I have a question about creating triggers after update. The situation is as follows: in my bank there are several tables that have foreign…
-
2
votes2
answers556
viewsInsert foreign keys
I have two tables and when I try to use a key of the 1st table in the 2nd the value appears NULL and should appear the values that appear in Aquario CREATE TABLE Aquario( ANome varchar(64) PRIMARY…
-
2
votes3
answers873
viewsDo not return a field value when it is zero
I’m creating a consultation on SQL, but I need a certain field not to display the values when it is zero. It is possible? SELECT gfilial.nomefantasia AS 'Filial', tmov.codtmv AS 'CODTMOV',…
-
2
votes3
answers102
viewsTake Report with zero months
I have a query in which I take monthly deposited values it takes everything it has in the base and shows the months that were entered in the base. I would like to do different I would like to show…
-
2
votes1
answer139
viewsSort results with month and year
I have a table with the fields mes E ano. How can I sort the results according to the month. I’m already ordering according to the year => SELECT * FROM tabela WHERE id_cliente = '$id_cliente'…
-
2
votes2
answers186
viewsHow to select single data from a Join conditional?
I have 2 database tables: Servers +----------+--------------+ | Field | Type | +----------+--------------+ | id | int(11) | | ip | varchar(255) | | votes | int(11) | | port | varchar(255) | | hash |…
-
2
votes1
answer452
viewsSQL, subquery if null
I’m doing a query, but I didn’t want it to return NULL. What I got is this: select ifnull(sum(job_withdraw_qty),0) as total, ( select IFNULL(sum(job_withdraw_qty),0) from job_positions where…
-
2
votes2
answers1004
viewsGroup table data with two columns
Well, I am in a incognita that I would like to solve directly in the SQL query, see this supposed example: TIPO | DE | IDENTIFICADOR ------------------------- 001 | 23 | 9 001 | 44 | 9 001 | 23 | 8…
-
2
votes2
answers74
viewshow to make this query sql
code is PK in both tabela1: cliente codigo, nome, municipio tabela2: notafiscal codigo, numerodanota, cod_cliente I want to list give a Count(*) on all notafiscal where cod_client.municipio = 10 how…
-
2
votes2
answers3352
viewsHow to fix accentuation query sql server data
Good morning! Guys, how do I correct the accents of the data coming from a select in sql server. For some records that were to come as Sergio, is coming SÃ rgio.
-
2
votes1
answer3011
viewsError Code: 1215. Cannot add Foreign key Constraint
Can anyone help me? I can’t create this foreign key. Just follow my code: CREATE DATABASE escola2; USE escola2; CREATE TABLE IF NOT EXISTS aluno ( matricula INT, nome VARCHAR(25), sobrenome…
-
2
votes2
answers100
viewsSQL query for Linq mvc4 c#
I’m not very familiar with Linq and I’m having a hard time turning this SQL query into Linq, can someone help me. I do the join of 6 tables (it wasn’t me who made the database. I have to work with…
-
2
votes1
answer38
viewsHow to return the expected result in this query?
Good afternoon, you guys. The case is as follows: I have a table with 2 blogs of category "auto" and part of the title "Hackers" so whatever my query, can not return more than two results combining…
-
2
votes2
answers363
viewsUsing & in Oracle Search
I’m having a question about using & on Oracle. See below my table. When searching for the description 'Easy Breezy Emailmkt & Eu', Oracle opens a window for passing parameter, as shown…
-
2
votes2
answers50
viewsdoubt with query in sql
I have a table with 5 fields: id name office salary date ...and wanted to make a query that returns the name of the people with the highest salary, of each position, and I have for example 3…
-
2
votes2
answers760
viewsHelp with mysql Kurdate()-1
I’m getting this mistake: #1064 - You have an error in your SQL syntax; I’ve tried so many ways, but there’s always this mistake. Here are two of my attempts: SELECT `category`. * , `event`. * FROM…
-
2
votes1
answer110
viewsSQL query using several times the same function
I have a function that converts the identification of a version to number, example, of 1.0.0 for 10000, because I can filter the results. Function: CREATE OR REPLACE FUNCTION…
-
2
votes1
answer480
viewsScript for comparing and updating Oracle database equemas
People would like to know if there is a program (or script) that compares schematics and updates in database, we work with a software that uses the Oracle database and every time an update implies…
-
2
votes1
answer607
viewsno such table: tbcarro
After following some examples, I am doubtful about the following error: 11-24 20:49:14.803 18215-18215/tiburski.rg.cadastrocarro E/SQLiteDatabase: Error inserting nome=ggggg modelo=ggggg placa=hhhh…