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
answers1063
viewsLeft John returning more records
I have a main table with about 5,000 records, and I need to search for information in another table with 7,000 records. But my query is returning +6,000: SELECT principal.id, info.nome,…
-
1
votes1
answer84
viewsWrite only one field to the database
How do I record only one of these fields select? Statement stmt = con.createStatement(); ResultSet RS = null; RS = stmt.executeQuery("select codplpag, descricao from pcplpag ORDER BY 1,2");…
-
1
votes2
answers1664
viewsUTL_SMTP: Sending Accents
Hello, I am using Oracle XE 11.2 to send emails using the UTL_SMTP package, but whenever there are accents to the subject or message, it is replaced by a "?". Here’s what I got: I have a protocol…
-
1
votes1
answer163
viewsHow to do this SELECT (SQL Server 2008)?
to be quite honest I don’t even know how to start my question. So I’ll first put the information I have. I have the following structure in my database. And I need to make a SELECT that returns to me…
-
1
votes2
answers623
views -
1
votes0
answers48
viewsDoes the mirror break influence the server audit?
Does the mirror break influence the server audit? I ask this because, in the databases where I need to redo the mirroring for some reason, I also have to specify the audit again…
-
1
votes1
answer138
viewsQUERY SELECT (oracle sqldeveloper)
Have the query below. SELECT 'A. ABERTOS' QUANTIDADE, (SELECT SUM(S) FROM (SELECT COUNT(*) S FROM VW_SOLICITACAO_DETALHE VW INNER JOIN SOLICITACAO SOL ON SOL.ID_SOLICITACAO = VW.ID_SOLICITACAO WHERE…
-
1
votes1
answer233
viewsSQL does not keep new recordings
I’m using a Service-based Database (.MDF) to save some data from an application I’m developing. However, after I close the application, the data that was entered in the table disappears. It follows…
-
1
votes1
answer177
viewsDISTINCT WITH UNION AND COUNT
I’m performing a query in the database to return 6 results from a table Agenda which has several schedules available per day (ex: 08:10:00:000 | 08:30:00:000) and for periods (ex: T (representing…
-
1
votes2
answers661
viewsSearch in a JSON encoding field
There is a field in the table where the content before being written is encoded in JSON. The content is saved as follows: [["nome_completo","Ana Concei\u00e7\u00e3o Dias"],["idade","27…
-
1
votes2
answers582
viewsHow to create a function that returns the lowest expiration date between batches of a given product?
How I create a function that returns the shortest expiration date between batches of a particular product? Dry my SQL code: create database Exemplo; use Exemplo; create table produto (codProduto…
-
1
votes1
answer571
viewsSort table by name
I have a table, which shows all the data from the Sqlite database. I wanted to sort by name all the data and present them. I have a hyperlink that calls a function to sort. The problem is it doesn’t…
-
1
votes1
answer2032
viewsExclusion of records in cascade tables
I have a "Terms" table that your ID is FK from "Thermosexpresso". As shown in the figure below. When I run the command "delete Terms Where Idtermo = 4" sql generates me the following error. The…
-
1
votes1
answer2653
viewsCalculation of the average in php
I need to calculate the final grade average of a class, I tried using the function avg SQL, but I was not successful, the code is this: <?php $idTurma = $_GET["idTurma"]; $idDisciplina =…
-
1
votes1
answer272
viewsSearch the database with encrypted data
I own a database where the entered data is encrypted through a function written in PHP, this function encrypts and decrypts. I need to search this table. For example, I search for "BRAZIL", but in…
-
1
votes0
answers108
viewsIs using 1=1 in WHERE wrong?
Is having a certain dispute whether or not the use of 1=1 in the where of a query in my team. Using this method to generate querys dynamically brings some harm in query performance or it does not…
-
1
votes1
answer648
viewsUnilateral replication in Postgresql
I have two servers. One is only and exclusively for testing. The other is for production itself. I need the test database to contain the same data from the production database. I can’t do a mirror,…
sql database postgresql synchronization replicationasked 9 years, 10 months ago Pedro Vinícius 1,870 -
1
votes1
answer821
viewsUpdate with JOIN in Mysql
I am updating to table A which will receive values from Table B in accordance with a.codigo = B.folha When you run the routine below, it is slow and nothing happens for a long time. It is 500,000…
-
1
votes1
answer854
viewsList-based WHERE filter with SQL
Good afternoon! Please, I am making a Fiscias Notes filter based on a series of Cfops with SQL. It works like this: SELECT * FROM NotasFiscais WHERE CFOP = 5101 OR CFOP = 6101 OR CFOP = 5922 OR CFOP…
sqlasked 9 years, 9 months ago Cassio Milanelo 791 -
1
votes1
answer361
viewsAlways include records from the other table if the value of the related field is not NULL
I’m doing a query query, based on a table. In this table (Tablea) I bring several records from other tables, with some codes but one in particular is giving me a certain headache. There is a record…
-
1
votes2
answers111
viewsTreating bank search dates
I’m performing the following capture of a date: $dtInicial = $this->_getParam('dataInicial'); // Padrão dd/mm/aaaa To search the bank precisely leave it in the standard yyyy/mm/dd: $dt1 =…
-
1
votes1
answer212
viewsProblem insert file name in database
I am uploading files with plupload using codeigniter. My problem is when there are special characters in the file name. Being that I have to record that original name. When there is for example:…
-
1
votes3
answers354
viewsReturn the last entry of different Postgresql objects
Supposing I have two tables: Car containing: plate, year, ect.. Event containing: car, lat, long, date, time, etc.. How could I return only the last entry of each car in the event table?…
-
1
votes1
answer563
viewsHow to check if a name is in the database?
I want to check if a name exists in the database; if there is no registration. Using the code below I can register several users with the same name. php. $user = $_POST['user']; $pass =…
-
1
votes1
answer554
viewsSQL returns two records to a field, how to join them?
I have the following SQL code in DB2: SELECT p.nome_pessoa, a.dt_nascimento, alc.matricula, d.numero_documento, d.id_tdoc_pessoa FROM pessoas as p INNER JOIN alunos as a ON p.id_pessoa = a.id_pessoa…
-
1
votes1
answer437
viewsLogical deletion of SQL Server records
We have the culture of making only logical exclusions in the application, keeping 2 fields where 1 is the date of exclusion and another char that gets’S' or 'N'. When we perform searches for deleted…
-
1
votes1
answer149
viewsOptimize SQL Query in three tables
I have a product table that has a foreign key that is the category and a table that stores the name of the product photos. I usually make two queries: one to retrieve the category name and some…
-
1
votes2
answers336
viewsAndroid: Problem searching last id inserted with Sqlitedatabase (ORM Lite)
I am having a problem executing a query (with Ormlite) that adds the return to 'ultimaConfiguration' in which you should get the last 'id' inserted in the Configuration table. the method that…
-
1
votes1
answer231
viewsImplement Follow/Stop Following functionality
I’m developing a followers system, created a page that does a search of registered users. You type in an input a name, and it checks if there are any records with that name in the database. I put on…
-
1
votes1
answer1769
viewsHow to insert UUID automatically into a Mysql Database?
Is there any way to insert a UUID automatically in a table field, in the same way as with a field of the type AUTO_INCREMENT? In a framework for PHP, Cakephp, when defining the primary key as…
-
1
votes1
answer100
viewsSQL only in custom Wordpress post for tag conversion
Let’s say a site using Wordpress has half the posts of the default type, and the other half using a Custom Post Type "review" http://codex.wordpress.org/pt-br:Tipos_de_Posts_Personalizados. But this…
-
1
votes1
answer282
viewsGive preference to greater equality, mysql
I have a table with a column called X in it I enter values separated by comma, for example: 1,2,3,4,5. Use this query to capture certain Row. SELECT * FROM 'x' WHERE CONCAT(',',x,',') LIKE '%,1,2,%'…
-
1
votes1
answer108
viewsSort result with 4 different columns
I have a table with 4 different columns, 2 of them indicating the beginning (date and time) and 2 other indicating end (also date and time). Is there a way to sort the result so that it prioritizes…
-
1
votes1
answer238
viewsRelationship Tables
I have a table Endereco which serves as much to Funcionario how much for Supplier: 1 Funcionario possui 1 Endereco 1 Fornecedor possui 1 Endereco How I create this relationship without having…
-
1
votes1
answer109
viewsreplication error
I’m trying to use a command on shell in Postgresql(Windows) with the following syntax: select pg_start_backup('nome do meu banco de dados', true); It responds to a record. Now, when I type the…
-
1
votes1
answer142
viewshelp with SQL Nvarchar
Hello, I had some problems with a code on SELECT... example: SELECT dados FROM banco WHERE CPF='$CPF' // com o código assim estava dando alguns erros pois o bd era em SQL e o Servidor windows. The…
-
1
votes1
answer4876
viewsHow to merge result from two tables 1 - n
I have the following problem. 1 table client that has relation with 1 table photos (respective photos from client) 1 client ratio for "n" photos; In short: client has id, name. photo possesses…
-
1
votes1
answer266
viewsSelect non-empty field
demo table id imagem flash codigo 1 fda.jpg 2 asdfasd.sfw 3 adsense is there any way to SELECT only the non-empty? if yes what is the best way in PHP or SQL? $sql = "SELECT * FROM publicidade ORDER…
-
1
votes0
answers55
viewsRetrieve all values from an SQL table and add to a session
I am using the following code to get all data from my table: $sql4 = mysqli_query($db, "SELECT * FROM login"); $exibe4 = mysqli_fetch_assoc($sql4); It’s working perfectly and it’s picking up all the…
-
1
votes1
answer315
viewsRead JPEG image, convert it to PDF and save to disk - Visual Basic 6
I will create a button, which when clicking it, it reads a JPEG image and can convert it to PDF and save to disk. I would like a tip in source code so I can start this project. Thank you very much.…
-
1
votes1
answer46
viewsHow to limit the results of a query in DB4O?
How can I create a query that returns a limited number of such results like the limit mysql? I’m looking in the documentation and I can’t find.
-
1
votes1
answer154
viewsReference the same table twice in another table
My question is this: I have to design a system for a healthcare institution that has internal doctors. There are users, and each user has an internal doctor. Each user also has family doctor of the…
-
1
votes1
answer84
viewsProblem with LEFT Joins joins and one condition
I have had this problem for some time. I count on your help. I have 3 tables: publicacao id cartaz titulo 1 eradogelo.jpg A Era do gelo 2 ojogo.jpg O Jogo 3 helpme.jpg Help Me 4 please.jpg Please 5…
-
1
votes1
answer85
views -
1
votes0
answers546
viewsAdd amount of gold to player
I have a server of [ Mu Online ] Ex 802 , and it has a { SHOP CASH } system so players can buy their items. Well my Server has a control panel in which I can add the amount of currency that the…
-
1
votes1
answer108
viewsHow to model a comment system
I am developing an application in Rails. I would like to know how to model the comments part. There is a table for the calls( Helpdesk system ), and the same relates to the history table, which are…
-
1
votes1
answer610
viewsStatement and SQL Run Error - Netbeans
try{ Class.forName(driver); Connection conn = DriverManager.getConnection(str_conn, usuario, senha); Statement stmt = conn.createStatement(); String sqlinsert ="insert into cheque…
-
1
votes5
answers923
viewsHelp with PHP and Mssql special characters
I’m making a form, and when I record the information with special characters, record it well... only when I rescue the information it comes encoded... already used , utf8_encode/Decode and nothing I…
-
1
votes1
answer203
viewssp_executeSQL for each record of a table
I have the following problem: I need to analyze the differences between two databases, based on the existing tables and columns within these tables. My idea is to take the name of the columns inside…
-
1
votes3
answers30209
viewsSQL higher date of a record before the given date
Next is the following case: Tb_importacao [cod_titulo,data,imp_situacao] cod_titulo data_imp situacao 1 2015-04-10 1 1 2015-04-11 2 1 2015-04-11 1 1 2015-04-13 2 1 2015-04-14 3 1 2015-04-14 4 I need…