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
answer150
viewsHow to sort the result of a query by a column where there is a value in another column in the same table?
I have a table with several columns, and I want to sort the results by the values of one column where another column in the same table is equal to a value. I have tried implementing the query with…
-
0
votes0
answers33
viewsProblem with postgresql server version Mismatch
I am trying to restore a base, small , I perform the backup on my machine in version 9.6 , but, alleges error when trying to create the backup via pgadmin III, executed through a bat : pg_dump.exe…
-
0
votes1
answer350
viewsInvalid SQL (INNER JOIN) indenter error
Select a list of employees who have changed positions or departments (job_history), the list must contain the employee’s registration and name, the name of the department and position that worked,…
-
0
votes1
answer51
viewsDatabase with many changes
Situation I’m making a system for a drug store. The Customer can enter the pharmacy and pick up products only from the gonad and pass directly to the cashier, or can pass the counter and pick up…
-
0
votes1
answer53
viewsUsing "select" in sql (oracle), failed to search
I have to settle the following question: 1.Consult EL NOMBRE (DESCRIPCION) DE LOS PRODUCTOS ADQUIRIDOS POR LOS CLIENTES HOOPS Y GOOD SPORT EN EL ANNO 1990. the command used for the search was:…
-
0
votes1
answer45
viewsHow to shrink a large query - Postgresql
In Visual Studio, we have the possibility to shrink a large code, IE, visually decrease the size, as a way to facilitate reading, example: #region Seu código aqui... #endregion I would like to do…
-
0
votes1
answer158
viewsJava createNativeQuery Insert datetime
I’m trying to insert into a bank whose dates are datetime2(7). SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Query u = em.createNativeQuery(insert); u.setParameter(1, sdf…
-
0
votes1
answer226
viewsHow to make a Join of 2 tables and where 2 fields of table A refer to the same field of table B?
I have the command SQL that doesn’t work: SELECT GAT_requisicao.id_GATrequisicao as 'ID Requisição', GAP_atendimento.id_GAPatendimento as 'ID Atendimento', GR_paciente.nome_GRpaciente as 'Nome…
-
0
votes2
answers98
viewsSelect data from three SQL tables
I am trying to join data from three tables using this sql: SELECT cod_nota, cupom, valor_contrato, valor_cadastro, data_emissao FROM cupons_nota, vendas, notas_fiscais WHERE cupons_nota.cupom =…
-
0
votes2
answers103
viewsHow can I select a range of items, after some values using SQL IN operator
For example: I want to fetch, 1,2,5,7,11 and then the rest up to 100, in a DQL SELECT. Ex.: SELECT column_name(s) FROM table_name WHERE column_name IN (1,2,5,7,11 ... value100); In case my doubt is…
-
0
votes1
answer498
viewsSQL doubts - two consolidated tables (excel sheets)
Hello. I have a question, which I believe is simple for forum veterans. I don’t have much notion of SQL, but I need to integrate two excel files One of stock and one of sales They are two different…
-
0
votes1
answer302
viewsProblem running SELECT in a phpmyadmin table
I have several tables in my database, and until recently, there was no problem in any of them. I was able to manage the entire bank smoothly by Phpmyadmin. But suddenly in one of the tables the…
-
0
votes1
answer464
viewsBegin Transaction and Save Transaction SQL Server
I have a Storedprocedure on a system I’m working on and I have the following code begin transaction; save transaction Integration_SP; -- CODIGO commit transaction; I have been searching and only…
-
0
votes1
answer38
viewsDoubt Case Sqlserver
I’m using the following case: CASE WHEN RESPOSTA.CD_RESPOSTA = 1 THEN 'ATENDE' WHEN RESPOSTA.CD_RESPOSTA = 2 THEN 'NÃO ATENDE' ELSE 'NÃO APLICÁVEL' END AS DS_RESPOSTA I have the value of…
-
0
votes1
answer66
viewsHow to put two records from one table into another as one in select Mysql Database
How to put two records from one table into another as one in select Mysql Database? SELECT TURMA.turma_id, TURMA.turma_nome, PROF.prof_name from turma TURMA LEFT JOIN professor_materia PROF_MAT ON…
-
0
votes1
answer368
viewsCharacter change at - sql position
To replace the third character of a string in Firebird, example: 00028 by 00128, 00029 by 00129... Someone could help me, I tried to see by replace, but I can’t determine the position
-
0
votes2
answers516
viewsUpdate or Insert with data from another table
I have this command SQL to update the tableREQUISICOES with the table dataREQUISICOES_ATUALIZA. Use as key to update the field numero_requisicao, but I need if not find correspondencia on the table…
-
0
votes1
answer48
viewsIf it has no value to compare, save without comparing
I’m trying to make my application save if it has no value to compare, however you are always going through the comparison, I tried to put an if but still problem, this is the class that makes the…
-
0
votes2
answers39
viewsHow to insert for all users in PLSQL when there is no data?
Good afternoon! I’m trying to insert to all users when there is no type entered for all users: INSERT INTO USUARIO ( TIPO, PRIORITARIO) SELECT '130', 'N' FROM dual WHERE not exists (SELECT * FROM…
-
0
votes2
answers25
viewsDifficulty mounting query for Search in multiple columns
I have 2 tables tab_user user_id | nome_user | tel_user 1 jão 888 2 mari 999 3 jão 777 4 mari 666 tab_product id_produto | user_id| carac_a | carac_b | carac_c | carac_d 1 1 aaa bbb ccc eee 2 1 mmm…
-
0
votes1
answer53
viewsSort menu by ID
I have a manageable menu, where you will need to organize items by ID. Each menu item corresponds to an ID. $rsm = exesql('SELECT * FROM produtos_categorias WHERE id_pai = 0 AND ativo = "S" ORDER BY…
sqlasked 6 years, 5 months ago Felipe Viero Goulart 3,693 -
0
votes2
answers604
viewsI can’t connect PHP to SQL Server 2014
Good afternoon, you guys! I created a small application to test my PHP connection with SQL Server 2014, but I’m not able to connect. I’ve seen numerous forums on the web and even here some questions…
-
0
votes0
answers90
viewsGroup weekend and holiday values for next business day
Guys, I have the following problem, I need to group all balance amounts that fall on Saturday, Sunday or holiday for the next working day. I have a table invoices with the values of saldo and the…
-
0
votes1
answer48
viewsSearch for NULL mysql via Java
I intend to save a residence in my database via java when one of the searched parameters is NULL, but it turns out I can’t find a way to pass that command. My code is: public Usuario…
-
0
votes0
answers569
viewsDatabase in "Restoring" mode
Good afternoon to you all! In SQL Server 2008, I needed to do a database conversion for one of our clients and I was going to do the backup in case there was a problem, only I mistakenly pressed to…
-
0
votes1
answer60
viewsReset sequence every year
I am creating an identifier that has the following formatting sequence/ano, for this reason I need my Quence count to 1, again, whenever there is a turn of the year. Is there any way to do this…
-
0
votes1
answer983
viewsRelationship 1 - 1
I’m having a little trouble designing my relational database model. The idea follows the following principle:: It would have a login system, and for that a table user There would also be 3 types of…
-
0
votes2
answers38
viewsProblem with running SQL through FORM
Php code: if($_REQUEST['alterarStatus']){ $alterarStatus = trataaspas($_REQUEST['alterarStatus']);} if($alterarStatus=="aprovado"){ $SQL = "update ps set StatusTransacao='Aprovado' where Referencia…
-
0
votes0
answers41
viewsUnique or something similar to 3 or more different tables
Sirs, In the company where I work uses an ERP that I do not know for what reason, is carried out the typing of sales notes, return of sales and returns of purchases in three different forms, and the…
-
0
votes1
answer47
viewsIsnull get the next SQL condition
how can I do on SQL server a condition if the return of a field is null and it returns another condition ISNULL( CONVERT(CHAR(08),C.PEDS_DAT_FAT,112), d.NFFE_DAT_ENT) BETWEEN '20180501' AND…
-
0
votes0
answers16
viewsJavafxml application with datepicker, insert value in BD
I have to enter the value of a datepicker that comes in DD-MM-YYYY format in the database and when I run the application I get this error: "com.microsoft.sqlserver.jdbc.Sqlserverexception: Operand…
-
0
votes1
answer860
viewsJoin between tables that do not relate directly
I have three tables: Candidate who has an ID as pk (which has been invented) Registration that has FK for Candidate ENEM that has no id representing the candidate, only his registration and…
-
0
votes1
answer1178
viewsWorking day function
The query below in datediff is bringing the difference of days correctly, but I just want to bring the amount of working days. I already have a business day function that excludes Saturdays, Sundays…
-
0
votes0
answers90
viewsHow do I record the data from a form in the database in Laravel 5.4?
I have a small problem in the production of a registration system, everything is working fine, but when I check the database no data submitted in the form appears, ie is not registered. Class in the…
-
0
votes1
answer435
viewshow to subtract column date with system date?
I have a date column data_novo and I want to know how many days the product is open, I have to make a subtraction account between the "system date" and the date that is in the column data_novo. And…
-
0
votes1
answer36
viewsShow message if IN record does not exist
I want to put several CPF numbers on IN of a query and if the CPF exists in the table show the data, but if it does not exist show a column indicating that it does not exist in the table. Exemplo:…
-
0
votes2
answers652
viewsConvert SQL query to Mongodb
I have little (or no) knowledge in non-relational banks. I need to convert the below query (Sqlite) into an equivalent query to be executed in Mongodb. SELECT COUNT(*) FROM match_table WHERE…
-
0
votes2
answers107
viewsSQL result in columns
I have an appointment Oracle SQL that returns the records per row, and I wanted to turn that into column. I did a search and find that the Pivot does this, but I don’t know how to use it, someone…
-
0
votes1
answer114
viewsorder by specific text
How do I make a order by by text criterion? I have a column with some ratings and wanted it to come in the order I determine. Example: 'carro1' 'carro3' 'carro5' 'carro10' 'carro2'…
-
0
votes1
answer41
viewsinsert table within another table
it is possible to insert one type of table inside another? Example: I have the BOOK table and, inside it, I want to create a column of type AUTHOR (referring to the AUTHOR table itself).
-
0
votes2
answers33
viewsCreating two links with path of a Explode
I am developing a project and next to the form, the user can upload a file. In this case, the registration part next to the upload(s) I already managed to do, now I am creating the display/change of…
-
0
votes1
answer146
viewsDoubt in an SQL query
Through this DER template I would like to make an sql query that returns the following information: Write a command that shows how many customers are single.…
-
0
votes1
answer340
viewsHow to compare two Oracle Datetime columns
I have a column where I enter a date when the event happens (local storage), and the date when the event is sent to my system. The difference between the date of the event and the date of dispatch…
-
0
votes2
answers110
viewstransform sql with subquery into query in Entity
I’m in need and I’m having trouble getting this sql with subquery and doing the same thing in c# Entity. SELECT Id,Nome, (SELECT Count(Id) FROM Pedidos WHERE Pedidos.ColaboradorId = Colaborador.Id)…
-
0
votes0
answers68
viewsProblems entering data from PHP to database
Below is the HTML code <?php include_once 'config.php'; ?> <!DOCTYPE HTLM> <html> <head> <meta charset="utf-8"> <meta name="viewport"…
-
0
votes2
answers427
viewsDifficulty creating summation column in mysql
I am making a committee report, but a doubt has arisen, I want to bring some totals at the end of the report such as the gross value of all committees, which would be the vl_comis - desc_comis.…
-
0
votes0
answers28
viewsBest way to build a class to run an SQL package
I am building a layer of access to the database and I need to access the functions inside a package on the oracle server. Orm already connects to the database and accesses tables and procedures…
-
0
votes1
answer43
viewsSelect values from another table with more than one row in Websql
I’m using Ionic + Ordova + Websql. I have basically these tables, partners and partiesEnderecos. In the address table can contain more than one row for each partner. How do I return these values? I…
-
0
votes1
answer3711
viewsFind difference between two tables
I wanted to mount an sql statement that returns differences between two tables. For example, I have the table arquivos and the table conferencias where it has equal fields called titulo and valor,…
-
0
votes1
answer123
viewsChange Gridview
I’m having a problem changing some information, in case I need to change two columns of a gridview, but they are coming directly from a database I need to change these two fields(Id_category and…