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
answer324
viewsConnect Java system to database on server
I have a Desk system in which I am trying to connect to a database that is on the server. But every time I try to connect the following error: java.sql.Sqlexception: null, message from server: "Host…
-
0
votes0
answers82
viewsReference of forein key, with the Entity Framework
I’m having a hard time making one Insert, because the FE indicates that there is error in the table reference. But, in my config, I state what is the foreing key. My config: public class…
-
0
votes1
answer92
viewsIdentification and marking of SQL script keywords within a Word document
I am making a system error manual for the company where I work. Within this manual you will have a description of the error as well as its solution. Many of the solutions are very extensive SQL…
-
0
votes1
answer56
viewsSQL Query according to the Make a New Column
I have a column that is numerical. In this column there are positive and negative values. I need to make an appointment that when I’m positive, I’ll consult Tabela A, when negative I refer to Tabela…
-
0
votes0
answers210
viewsshow similar product/property with php and mysql
I am developing a feature on my site to show similar properties by title and value 9r, but it did not work very well my idea: <?php //Armazeno o resultado do titulo da consulta anterior da tabela…
-
0
votes1
answer115
viewsQuery in 3 tables and comparisons with sql
Good night! I’m at an impasse here. I’m thinking of the best way to solve a solution. The problem is this: I have 3 tables with the names of Monsters, items and inventory. The Monster has an…
-
0
votes1
answer526
viewsForeign key php database
create table cliente ( id_cliente integer auto_increment, nome varchar (100), primary key (id_cliente) ); create table produto ( id_produto integer auto_increment, id_cliente integer, nome_produto…
-
0
votes1
answer141
viewsSP_HELPTEXT without formatting
When a Trigger is compiled by TOAD for SQL, using the F9 button and not F5, it is inserted into syscomments with wrong formatting, as if it were a single line, where line breaks are disregarded. The…
-
0
votes1
answer275
viewsParameter-based query in SQL Server
I have a situation where I need to bring results depending on the parameter reported. If I gave you any number, which would be the code, it would only bring the result that has the code. If I didn’t…
-
0
votes2
answers258
viewsMysql, selecting 4 related tables
I am trying to make a select on 4 different tables. They are all related. It all starts with the Resident. SELECT morador.* ,unidades.* ,grupo.* ,condominios.* FROM morador LEFT JOIN unidades ON…
-
0
votes0
answers183
viewsDifferent results for Mysql 5.1 and 5.7 query
We developed a project for a client using Mysql 5.1.68 and at the time of publication we identified that the client’s hosting had version 5.7.4. After publishing the project, we started to check…
-
0
votes0
answers43
viewsCan I use the result of the Case clause as a field in Select?
This question refers to this: How to return day of week and time formatted sql server 2008? I’m trying to fix it: SELECT CASE DATEPART(DW, GETDATE()) WHEN 1 THEN 'DOMINGO' WHEN 2 THEN 'SEGUNDA' WHEN…
-
0
votes0
answers113
viewsPerform subtraction using aggregation functions
I have a table immovable with the fields of code, price and area. I need to find out what is the price difference between the largest and the smallest property in the table (in a matter of area). I…
-
0
votes3
answers476
viewsSelect Oracle returning numerous times the same result
My select works and returns the data I need, but it is returning more than 6000 times the same result. How do I get it to return the result in just 01 line. NOTE: There is only one result for this…
-
0
votes1
answer1180
viewsSQL - Update without losing values
Good personal my doubt is the following I would like to update a value in the "Database" without losing the value there already allocated, Good for better understanding of my doubt I would quote an…
-
0
votes1
answer509
viewsFriends system in PHP and SQL
I have a problem and I haven’t found the solution yet. I have 2 tables, one of users and another of friends. In the user table I store the id and the username On the table of friends I have the…
-
0
votes1
answer2210
viewsOrder by with Union
I have the following tables: Pessoa1 Id | Nome | Cidade 1 | José |São Paulo 2 | Maria |Rio de Janeiro Pessoa2 Id | Nome | Cidade 1 | Pedro |Belo Horizonte 2 | Ana |Vitória I have the following…
-
0
votes1
answer697
viewsPHP ORACLE VIEW FROM SELECT
I intend to generate a view through a select with the code below, but it doesn’t work, which may be? $row[0] contains "select col1, col2, col3, col4, col5 from tabela1" $select=…
-
0
votes2
answers165
viewsHow to consult a table in a limited (partial) way?
I need to consult a table extracting from it the Infos: <nome> and <pontuacao>, my tcc consists of a game in which one of its options is to see a ranking of registered players. as there…
-
0
votes1
answer76
viewsRemove duplicate records from a table
Having the following tables without keys still defined: Aeroplane (code_aviao, code_company, year, type_engine, type_airplane, status) Flight ( Flight code, Flight number, plane code, code_company)…
-
0
votes1
answer62
viewsDetermining value within a pivot
I have a query in which you are making a pivot and she’s bringing in the correct records per month, but I’d like to validate the amount of records per month that show only employees who have >=…
-
0
votes1
answer185
viewsWhen I pass date filter for the same day, query comes back empty and there is data
In my table/base there is data for the day 05/08/2015, happens that when I pass a date filter for the same day, it doesn’t work, it returns empty. If I pass like this: 04/08/2015 and 05/08/2015…
-
0
votes3
answers258
viewsHow to generate SQL in relationship table without repeating values?
I have the following scenario: Tables: Video (id, url) VideoCategoria (id, id_video, id_categoria) Categoria (id, descricao) I need to get the last 120 categories that received videos. On the same…
-
0
votes1
answer193
viewsSave all PHP results to a single HTML table
On my host there is an index.html with a form that is linked to a login.php that takes the results that the user typed and saves in an HTML table at the site root. The problem is that a table is…
-
0
votes1
answer1089
viewsIF conditional within SQL query
I have the following appointment: $string = " SELECT DISTINCT(idClientes), nome FROM clientes WHERE idClientes IN ( SELECT idClientes FROM planosclientes WHERE idPlanosClientes IN ( SELECT…
-
0
votes1
answer22
viewsJoin table photos to query
I have the following query that picks the user’s bookmarks ID=X $sql="SELECT * FROM user WHERE id IN (SELECT user_2_id FROM favoritos WHERE user_1_id =$id_user_logado)"; Now, how can I get the user…
-
0
votes1
answer29
viewsstmt prepare me nothing appears to me
I have this code to print the data on the page coming from the database: <?php session_start(); include "conection.php"; $id_login = $_SESSION["id_login"]; $stmt =$db->prepare("select…
-
0
votes0
answers458
views -
0
votes2
answers62
viewsDoubt using RIGHT JOIN in Sql Server
How could I return the results of these three tables, even if I did not have a relationship between them. I thank you SELECT A.IDPLANOCONTAS, A.NUMERO_CONTA AS NUMERO_CONTA1, A.DESCRICAO_CONTA AS…
-
0
votes1
answer894
viewsForeign key registration query with multiple occurrences
I am developing a system for storing documents for everyday use with PHP and mysql and for easy queries I added tags to these documentations and to ensure the integrity of the data I added another…
-
0
votes0
answers121
viewsCopy a record from a database with several related tables
I’m trying to copy a record from a database table, but the problem is that this table has a lot of links, foreign keys. The record should involve about 40 tables. Is there any way I can do this? I…
-
0
votes1
answer49
viewsWhy a Stored Procedure generates different results if run in Workbench and Java with JDBC
I have a Stored Procedure in Mysql that is working normally when running from Workbench, but by running this same procedure in Java/JBDC I am getting wrong values and different from those obtained…
-
0
votes1
answer61
viewsHow to calculate timestamp in SQL
I have an INT Field (status) in the database, I have a script that updates it every 5 minutes using php time(). How do I calculate via sql? Follow the select I’m using. SELECT * FROM users WHERE…
-
0
votes1
answer1538
viewsSelect min() returning value other than 0
I need to make one select where you take the lowest value found, other than 0 (zero), SELECT MIN(VALORTARIFA) MENORTARIFA FROM TABELA In the above command, if there is some value 0.00, it will…
-
0
votes1
answer195
viewsBecause my LIMIT does not accept variable
ERROR: it simply does not query when playing on a foreach because LIMIT does not become the variable I declared Does anyone know me? $cont = 2; $stm = $pdo->prepare('SELECT sol_camiseta.id,…
-
0
votes1
answer58
viewsSQL Server Transaction Replication - Primary Key
I have an environment with 2 branches, each branch has to have an application server with an SQL SERVER installed, I have configured the transaction Replication which is working perfectly, but if 2…
-
0
votes1
answer201
viewsSQL/ JPQL query
Friends, good afternoon. I have a table in the database called Question Inside the table I have two columns that are code (id) and question. I have a filter that I can not specifically bring only…
-
0
votes1
answer137
viewsSql - Merge select - Create Row if nonexistent record
I’m willing to join two SELECT, but I am unsuccessful. Has the following tables: CREATE TABLE tb_producao ( cd_producao SERIAL, cd_setor integer, nr_quantidade numeric(12,2), ds_producao character…
-
0
votes1
answer308
viewsIncorrect syntax near '-' in Insert
I developed an application for registration of Clients "Transport" linked to a database "MDF", when trying to save to the database gives error: "Incorrect syntax near '-'" I tried everything,…
-
0
votes1
answer1470
viewsHow is a specialization implemented in a bank?
In my ER model and diagram I created a specialization for an entity called clients, where it relates to the physical and legal entities derived from this specialization. I simply create the…
-
0
votes2
answers88
viewsHow to update the last name of a person who starts with the initial 'Fabio%'?
It is possible to do this, I have a name of a person who is 'Fábio Mello' and I want to update the name that starts with 'Fábio%' to have the last name '%Borges' as I do this query? update pessoa…
-
0
votes1
answer275
viewsCompare all records in table "A" with each record in table "B"
I am a programmer and rarely use database, I came across an unusual situation of converting multiple files . DBF and save everything in the bank on their respective tables, however some files exceed…
-
0
votes1
answer599
viewsQuery Performance - Postgresql
I have the following situation, I need to bring data from a vehicle table of the system in which I work and another with integrated data of a partner system, for being integration the data are not…
-
0
votes1
answer170
viewsSqlupdate does not change data in the database
Note: Several people could not solve this question and marked my question as erroneously duplicated because of an answer in a similar question but the answer does not help me at all. I am developing…
-
0
votes1
answer194
viewsRefresh a div with sql data without reloading the page
Hello guys I’m making a site in php, in which there is a section of buttons. When I select a button, you should do a BD search and with the result, update a div under the buttons, without reloading…
-
0
votes1
answer117
viewsrecover Datetime in Mysql between current date
In my database I have 2 fields: "data_start and data_end". From a current Datetime, I need to select all dates that are in the range that date_time >= data_start AND date_time <= data_end. I…
-
0
votes1
answer47
viewsDisplay SQL results with specific field filters
I have the SQL: select id,disponibilidade,tipo from clientes where cliente = '$cliente' AND status = '2' AND tipo = '0' OR disponibilidade <> '0' OR vanual <> '0' OR vtemporada <>…
-
0
votes3
answers958
viewsQuery in two fields of a table
Good afternoon, you guys I use two tables provides and occurrence - and I have 1 occurrence for N provids. I need to perform a record query that brings up how many provisions has the occurrence.…
sqlasked 8 years, 8 months ago Juliana Tavares 1 -
0
votes0
answers50
viewsProblems with scope in php, can anyone help me please?
I have some classes, I will post them to you can then explain my problem which is quite simple. class connection to the database <?php /* * Gerencia conexões com bancos de dados, * usando…
-
0
votes3
answers3825
viewsFormat date in SQL SERVER
I need to make a SELECT in my SQL Server 2008 database and I’m not getting it. I need to convert a date to the formatted one yyyy/MM/dd HH:mm:ss, however I need to convert in any way that works in…