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
votes2
answers235
viewsLimit 1 line in queries with primary key queries
One of the best practices on optimization of Mysql queries, dictated in an internet source, says that it is important to limit as 1 the queries that already display only one line. For example, if…
-
1
votes1
answer13610
viewsPercentage calculation in SQL SERVER
I have a little doubt that I am not able to solve, I looked here in the community, but I did not find exactly what I want. My situation resembles the following: I have N product records in my…
-
1
votes1
answer94
viewsOracle SQL Error Invalid Number
I have the query below, which shows me date and time, saved as default sysdate oracle: SELECT TO_CHAR(DATA, 'DD/MM/YYYY hh24:mi:SS') D1, TO_CHAR(DATA_FIM, 'DD/MM/YYYY hh24:mi:SS') D2 FROM…
-
1
votes1
answer29
viewsRelatedd and two tables
Guys, I have two tables and I need to connect them. I’m doing it this way: SELECT lancamentos .* FROM lancamentos INNER JOIN clientes ON lancamentos.cliente_id = clientes.id ORDER BY clientes.nome…
-
1
votes1
answer45
viewsSelect accessing two tables
I have a Product table, with the fields Marker, model and type. A second table referring to laptops has its fields related to price, RAM, other fields and the model, which is the same as the Product…
-
1
votes1
answer3140
viewsGroup values of different columns into one, comma-separated
I got the following select: SELECT DISTINCT ORGAO, UNIDADE FROM TESTE Where the following result is generated: Órgao Unidade 1 2 1 3 1 4 1 5 Four records of the same organ are returned, but with…
-
1
votes1
answer118
viewsInsert into does not return
I have the following table: Query with Insert public function CadastrarArquivos($pdo, $arq_nome, $a_areaid, $u_userid){ $ins = $pdo->prepare("INSERT INTO arq_arquivos(arq_nome, a_area_a_areaid,…
-
1
votes1
answer103
viewsInsert an ID into SQL+PHP
I’m making a form where the user inserts the data and the same receives the confirmation along with a ID record in php with sql, I’m just not getting this final confirmation along with the id,…
-
1
votes1
answer143
viewsI’m having trouble connecting SQL with java
Well... I did some classes, and it was time to connect to search for a data in the bank; Ok. He had already connected with the BD, however, when I did the class to fetch the data, he keeps giving…
-
1
votes1
answer1122
viewsDisplay text field in dbgrid Delphi
I have a DBGRID, and I need to show him a field like text, but when it shows, it appears (MEMO) instead of the text that was meant to be, as I do to make it appear? Note: I cannot change the…
-
1
votes1
answer161
views -
1
votes0
answers85
viewsPIVOT Help - SELECT SQL
I have a table with the data: unidade tipo valor 1 2 10,00 1 3 15,00 2 2 16,00 3 3 10,00 3 1 25,00 I need to make a select with pivot that brings me unidade tipo1 tipo2 tipo3 1 0,00 10,00 15,00 2…
-
1
votes1
answer447
viewsTable Analysis with Execution Log
I have a table in Oracle 11g with the following structure: CREATE TABLE USER.LOG_EXECUCAO ( ID NUMBER, DATA DATE, QTD_REGISTROS_INSERIDOS NUMBER, TEMPO_EXECUCAO VARCHAR2(50 BYTE) ) An example of…
-
1
votes2
answers179
viewsChecking date within a range in SQL
I need to check in my SELECT if the field e. Dating back to is between 30 and 90 days from today’s date. How to make the condition in CASE ? SELECT e.NmrCnt AS [Contrato] ,e.NmrSerie AS [Serie]…
-
1
votes1
answer201
viewsHow to measure the amount of disk space required for an ALTER TABLE operation?
I need to make some changes to one of the tables to add new columns. The problem is that I cannot do it. I get the following error: PG::Diskfull: ERROR: could not extend file…
-
1
votes1
answer223
viewsHow to select a larger number of records based on another SQL table
I have an IMMOBILE table ID | Tipo | endereço 1 | Casa | Rua teste 2 | Casa | Rua teste 3 | Apartamento | Rua teste And a sales chart id | ID_do imovel 1 | 1 2 | 2 I need to know based on the sales…
-
1
votes0
answers132
viewslike %TEXT% in full text search
I would like some help regarding the search using full text search in SQL Server. Today I have a table that stores materials and I’m doing a search using full text search with contains getting like…
-
1
votes3
answers1437
viewsFind higher sum value and show id
Talk guys, all right? I have this table Table EMPREGADO_PROJETO +--------------+-------------+-------+ | rg_empregado | num_projeto | horas | +--------------+-------------+-------+ | 20202020 | 5 |…
-
1
votes1
answer1611
viewsMysql UPDATE with JOIN and WHERE
My tables EMPREGADO Cod_Emp, Nome_Emp COMPANHIA Cod_Comp, Nome_Comp TRABALHA Cod_Emp, Cod_Comp, Salário, Cod_Emp_Supervisor I want to give a 10% increase to all company supervisors' test'. UPDATE…
-
1
votes1
answer312
viewsInsert range of numbers into an automatically SQL table
The point is that I want to insert in a table field a range of numbers that goes from 100 to 1,000,000 and I didn’t want to be doing 1 to 1. How can I do this automatically? In SQL Server…
-
1
votes0
answers48
viewsHow to create server certificate in SQL Server?
I’m creating an app that uses SQL Server as a DB manager. My problem is in making a secure connection between the DB and the application, so I need to create a server certificate within the SQL to…
-
1
votes1
answer61
viewsSQL data count filtered by multiple tables
I have a PHP page where I have to generate a chart of "Registered sellers" filtered by region. The problem is that the Sellers table has City Id, the City table has State Id and the State Id has…
-
1
votes0
answers225
viewsOperations with calculated fields from a mysql view
Good afternoon, I have a view where there are several fields where I have several calculations, and the result of these calculations I would like to use in other fields of this same view. An…
-
1
votes2
answers573
viewsHow to search a table by date and add values contained in it?
It’s the following guys, I’m having a lot of trouble creating a search by date in my android sqlite database. I wanted to search the tables by date, if possible, I wanted to make a condition that…
-
1
votes1
answer798
views -
1
votes1
answer37
viewsProblem with SELECT
I have the following SELECT SELECT t.nome, count(t.id) FROM Partidas p LEFT JOIN Times t ON p.codTimeCasa = t.id OR p.codTimeVisitante = t.id GROUP BY t.nome I would like him to return the teams…
sqlasked 8 years, 1 month ago Ismael Hartmann 11 -
1
votes1
answer810
viewsMysql backup by java
Good afternoon, I have a cmd that correctly backs up my database, but when running in java it does not open the cmd in the expected way, it follows the code: package sistemaMiriam.backup; import…
-
1
votes1
answer82
viewsCapture last INSERT value
I am creating a news system where the user has the option to register the news and put the original link where the news was generated, so far so good, the problem is that I want the user to have the…
-
1
votes1
answer70
viewsHow to use having together with view in sql server
When trying to use the HAVING in an SQL query is returning the following error: Mensagem 8121, Nível 16, Estado 1, Linha 15 Column 'V_DADOSFUNC.FILIAL' is invalid in the HAVING clause because it is…
-
1
votes2
answers137
viewsWordpress - How to include new fields in the user table?
I want to include the following fields in the registration of registered users in my blog: IBGE, Municipality and UF. How do I include these fields and later access them on a specific page?…
-
1
votes3
answers76
viewsError using HAVING in date/time query
I have the following appointment: SELECT ROW_NUMBER() OVER(ORDER BY V.DATA ASC) AS ID, V.CHAPA AS CHAPA, F.NOME AS NOME, V.DATA AS DATA, CASE WHEN V.BATIDA IS NULL THEN 0 ELSE V.BATIDA END AS…
-
1
votes2
answers54
viewsConversion of SQL Server types
I got the following SELECT in SQL Server: SELECT th.CidadeCod, th.ContratoCod, CONVERT(DECIMAL(5,2), ( SUM(th.PlacasLidas)/SUM(th.Trafego) ) * 100) AS [IndiceOCR] FROM controle.TrafegoFaixaHora th…
-
1
votes1
answer261
viewsDirect sum in PHP
I have a service control system. I would like to issue a service report and add up those figures but I did not want to do with the command on sql want to do right in the php, type sum of column…
-
1
votes1
answer156
viewsQuery ORDER BY dynamics from the selection of a combobox
I’m developing an application on java managing a database. This application primarily performs a SELECT the database, then submitting the ResultSet for an editable table. I tried to add a comboBox…
-
1
votes4
answers594
viewsReturn value in SQL Server query
I need this appointment to return 2 instead of A. TIPOUSUARIO is the varchar type. someone can tell me where the mistake is? USE DATABASE SELECT TIPOUSUARIO FROM TABLE UP (NOLOCK) WHERE TIPOUSUARIO…
-
1
votes1
answer52
viewsQuery with jpa + Hibernate with more than one idt in clause
with Hibernate I can make an inquiry by idt as follows: entityManager.find(Empresa.class, idtEmpresa); And that would already return the mapped object of the company class, but what if I wanted to…
-
1
votes1
answer653
viewsCuriosity - PHP and Data Query Limit
Today while doing an appointment by Phpmyadmin of the type SELECT * FROM tabela , I noticed that after making a query in the database automatically the query gets the LIMIT, in this way SELECT *…
-
1
votes1
answer1045
viewsInsert large amount of data into sql server
I downloaded a list of cities on the internet. There are more than 5,000 municipalities. I tried a simple Insert and could not. Exceeded the maximum number of 1000 records. Then I tried with Bulk,…
-
1
votes1
answer334
viewsHow to merge 8 query returns into one?
I have 8 query’s all have 5 unusual columns and some distinct columns, Based on the common columns I can display a single result of the 8? Common fields: F.CHAPA AS CHAPA, F.NOME AS NOME, F.FILIAL…
-
1
votes2
answers351
viewsDoubt with mongodb test
I am a beginner in Mongo I have a question with select/query. I need to make a query that searches at the base Yoda and in the collection configuracoes return all documents that hold the key…
-
1
votes1
answer1578
viewsDelete record when a column date is reached
I have the tables: In anuncios got the spine expiracao which receives the amount of days that that notice is valid, I want each day that the database automatically decreases 1 in this column, a…
-
1
votes1
answer584
viewsCreate Precedent to adjust price as per conditions (SQL Server)
In a comic book of a bookstore need to create a precedent to readjust the price column according to the percentage and gender reported (using transaction control). Like I should do? create table…
-
1
votes1
answer4608
viewsHow to compare a date of type datetime?
I have a date in a patient table in the Sql Server database in the following format: datetime (01/01/2016 12:50:00.000) I want to check if the patient’s appointment time has arrived. For example:…
-
1
votes2
answers106
viewsassign radio value found in sql - Codeigniter
I want the user to be able to see the data you entered in your log when loading the data update page. I can see the data that is in type=text but not in type=radio. View: <?php foreach…
-
1
votes2
answers71
viewsSelect from all companies that have catalogues
I’m having a problem at a select in two tables that are returning the value twice. I have the table businesses and table catalogues which are linked by company id. and catalogues.id_company. When I…
-
1
votes1
answer127
viewsZend Framework - Where are the queries?
I have an application using Zend Framework, in the structure MVC, I want to know where the queries to the bank are made, I’m a little lost because I never worked with Zend. In my model I urge, for…
-
1
votes0
answers113
viewsAccess - put data from a table horizontally
Hello! I have already searched in several forums, but I could not find a satisfactory solution. I have the following table: ID COD VLR_REEMB N_FICHA DT_RECEBIMENTO 1 1 4.022,06 965 24/09/2010 2 3…
-
1
votes0
answers98
viewsNotification by Browser
Hello my name is André Neto, I am developing a software, and within it there is a central mail, where the user can send an email from within the system and I store this sending data. Now the…
-
1
votes1
answer53
views -
1
votes1
answer83
viewsCheck 2 and 10 days before and 2, 5 and 10 after due day
Every month I need to send messages to customers 10 and 2 days Before of Expiration Day, and 2, 5 and 10 days Afterward of Expiration Day, I’ve broken my head and I don’t know how to do it: IF…