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
votes2
answers1453
viewsIndex views in Mysql
I have a view in my Mysql database, I would like to know if it is possible to index the fields that are contained in it, because I have a group by on it that is consuming much, and a index would…
-
0
votes1
answer476
viewsReturn a CURSOR from a Sqlserver using dynamic sql (sp_executesql)
In the oracle I can do as follows : OPEN MY_CURSOR FOR 'SELECT * FROM MY_TABLE' How to get this result in Sqlsever? I want to return a cursor by mounting a dynamic sql in the Procedure. I’m…
-
0
votes2
answers764
viewsHow to query data from a table using INNER JOIN in a sub-query in PHP
I have the following SELECT to select data from a table (chat) in a chat system: SELECT * FROM (SELECT * FROM chat WHERE id_chat = '$chat_id' ORDER BY id DESC LIMIT 10) S WHERE id_chat = '$chat_id'…
-
0
votes1
answer3861
viewsCatch the time of formatted sql server database
My database has a difference of 4 hours, support so far has not given a solution, so I would like to know how I can format the time out: select CAST(HORA_FECHAMENTO AS datetime) as HORA_FECHAMENTO,…
-
0
votes0
answers229
viewsHow to create database via sql and utf8_bin?
I have the following sql script: CREATE TABLE IF NOT EXISTS `pais` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nome` varchar(60) DEFAULT NULL, `sigla` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) )…
-
0
votes1
answer383
viewsHow to mount a generic query using jpa nativequery
Consider the following table: table: info_people ||Row ||first name||last name ||nationality ||time_do_heart |1|Marcelo |aragao |brazil |sp |2 |maria |Fonseca |brasil |sp |3 |Joao |timotio |brazil…
-
0
votes1
answer51
viewsMaintenance plan SQL Server 2014
I created a master plan in the bank of the company in which I work, the same is dealing with the following options: Check Database Integrity Shrink Database Reorganize Index Rebuild Index Update…
-
0
votes0
answers340
viewsexceeded the 'max_user_connections' Resource (Current value: 3)
Good evening, everyone. Dude I hate this mistake and I have no idea how to fix it. I’m closing the connection with the bank after every request but still. I am using PHP. Someone knows how to fix…
-
0
votes1
answer63
viewsSqldatareader Not Closed?
Imports System.Data.SqlClient Public Class F_Contentor Dim F_Topo As New Form2() Dim F_Principal As New Form3() Dim Prof_Ses_Nome As String Dim Prof_Ses_Id As Integer Const cs As String = "Data…
-
0
votes2
answers1523
viewsDoubt with DROP COLUMN sql server command
I tried to delete a column from a database, checked that there are restrictions. ALTER TABLE dbo.TB_ESTRACAO DROP COLUMN MULTIPLIER I get a message, how can I resolve this? I thank you! Message…
-
0
votes0
answers37
viewsIs it right to identify the columns in the database tables?
I have a question: In large projects, which require a lot of relationship between the tables, many Joins, identify each column with the table, for example: Instead of: Table name: users id | name |…
-
0
votes3
answers1696
viewsHow to transpose rows into columns?
It’s already been answered by Motta, thank you for your patience. How can I transpose rows to columns in Sqlserver, so something like that: Stick to this format?…
-
0
votes3
answers204
viewsOrder by or filter in Sql Server
It’s possible to use order by or some filter in Ner Join or left Join or I’m trying to do it wrong. I need to bring in a query a column that is in a daughter table, but I need it to be the column of…
-
0
votes1
answer74
viewsSelect ruby complex on Rails
I have a model that describes the friendship between my users: #CreateFriendship.rb class CreateFriendships < ActiveRecord::Migration def change create_table :friendships do |t| t.integer…
-
0
votes0
answers33
viewsSearch from a form
I have a form with all the districts of portugal. When I select a city I do the search through the method post, get the value city and research shows everything that exists with the city…
-
0
votes1
answer227
viewsGroup SQL values by two fields
I’m trying to group a table so I can make a Count, but I’m having difficulties. The structure of the table is as follows: ID - NOME - IDADE - ESCOLARIDADE 1 - João - 15 - Ensino Fundamental Completo…
-
0
votes1
answer908
viewsUncaught Error: Call to a Member Function prepare() on null in
I am trying to register my customer address and he gives the following message: Uncaught Error: Call to a member function prepare() on null in I have no idea what it might be, I query it this way:…
-
0
votes1
answer342
viewsHow to Update Stock Using a CSV File
I am using a manual stock synchronization module created by Brtsync, but I need to perform an automatic synchronization process, for example, consuming the fields of a CSV already generated by…
-
0
votes1
answer814
viewsIs there any way to merge multiple SELECTS into just one query?
I have a page where I will have to make several queries to the bank. At the moment, they are a total of three tables. They are: cadastro, publicacoes and estilo. Currently I do as follows: SELECT…
-
0
votes0
answers176
viewsMSSQL: SQLSTATE[] (null) (Severity 0) after loading 1000 lines
I have some reports where I need to perform new SQL queries in the loop. These reports are running in PHP and datatables. In some moments, when the number of lines reaches a volume greater than…
-
0
votes2
answers102
viewsSQL - Use of Distinct
Friends need a Select that loads: (all portals linked to a user and an additional column informing which portals were selected in a given news) So far my SQL is like this...: select distinct case…
-
0
votes1
answer126
viewsRelationship in database table
I have a registration form where contains personal information, professionals, additional, financial and production, my doubt, as it gives many columns, I believe that more than 50 fields. Is it…
-
0
votes1
answer358
viewsHow to set the boot value of a PRIMARY KEY field set to IDENTITY in SQL Server?
In Mysql when creating a table with an AUTO_INCREMENT field being PRIMARY KEY it is possible to define what will be the initialization value of the first record of the same, as follows the script…
-
0
votes1
answer470
views -
0
votes1
answer110
viewsSuggestion SQL generator on embedded system
I have an embedded system that stays in the client, but I need to develop an SQL generator that is open access to consultants and invisible to the client, IE, with a shortcut key it opens the SQL…
-
0
votes2
answers2013
views -
0
votes1
answer90
viewsCreate query with date range in Doctrine 2.0
I’m trying to get the records that are processed No (Datetime) less than 2 days from the current date. I am starting from the following reasoning. public function…
-
0
votes0
answers364
viewsTraverse all strings by delimiter in the field and generate a column with the result
SET @contador := 0; SELECT SUBSTRING_INDEX( SUBSTRING_INDEX("BOX 01;BOX 02;BOX 03;BOX 04;BOX 05;BOX 06;BOX 07;BOX 08;BOX 09;BOX 10;BOX 11;BOX 12;BOX 13;BOX 14;BOX 15;BOX 16;BOX 17;BOX 18;BOX 19;BOX…
-
0
votes3
answers241
viewsHelp with Subquery in SQL?
I have in my system a table called Agendas, this table is linked with other tables Class and School through the columns turmas_id and escola_id. What happens is that the column turmas_id is not a…
-
0
votes1
answer76
viewsHow to make 1 query and distribute the result spread by the code?
Well I have a site where I am to each area using a select , I think I’m making more queries than I should, is there any way to repeat the result ? follows a picture of what I am proposing <?php…
-
0
votes3
answers2051
viewsDifference between dates on multiple lines
Is there any way to make a DATEDIFF/LEAD/LAG in SQL Server to calculate the difference between dates taking into account the date of the previous/next record. SELECT SELECT NUM, CLIENTE, EMISSAO…
-
0
votes3
answers3965
viewsCheck the existence of Dice?
Is there any way to use a Script check if an index already exists in a table? I got the following script that generates an index in a table: CREATE NONCLUSTERED INDEX [meu_indice] ON…
-
0
votes2
answers523
viewsCompare two fields between different tables
I have a big problem. This is the following I have the Script below: <?php $contarperfilclientecontar = "0"; $sqlxml = "SELECT id ,vvenda FROM imoveis WHERE cod = '1042' AND status = '2' ";…
-
0
votes1
answer644
viewsProblems when working with dates in the database using a maskedtextbox in dd/MM/yyyy format
I am using a Maskedtextbox in BR culture to force the user to fill in the date in the correct format (dd/MM/yyyy). I remove the Maskedtextbox string to insert into the database and record…
-
0
votes1
answer194
viewsHow to do a search in an app using Angularjs with correct parameter passage?
How to do a search in an app using Angularjs with parameter passage correctly, when I speak correctly I refer to avoid SQL injection. For example, the parameter var parameters = "joao"; in the query…
-
0
votes1
answer457
viewsChamp inconnu error dans on clause - SQL
I have the following situation, with 3 tables: ocorrencias: Has 6 columns: tipo_falha_1 until tipo_falha_6. It’s a two-digit code, from 1 to 20. tipo_falha: Has a description of the faults. The…
-
0
votes1
answer62
viewsDoubt Beginner SQL
I need to know what the following queries accomplish, but I am doubtful, because I am starting to study SQL now. You can help me? "SELECT user_id, CAST(SUM(points_per_badge) AS INT) " + "FROM…
-
0
votes1
answer43
views -
0
votes1
answer42
viewsPHP error with Mysql
I’m making a mistake, and I don’t understand why. The mistake: Fatal error: Call to a member function fetch_assoc() on boolean the excerpt from the error: require 'conecta.php'; $sql = "SELECT…
-
0
votes1
answer1113
views -
0
votes2
answers74
viewsProblems to generate SQL command
Hello, everyone. I am creating a project that handles user registration. In this project there will be several types of users. To simplify, let’s call the types 1,2 and 3. Depending on the type of…
-
0
votes1
answer1685
viewsC# - Display search results in Datagridview (SELECT SQL)
Hello! I’m actually starting at C# and I already have small projects. I can already connect to the remote database, I can already run queries, I just can’t get the result of a Select and show in a…
-
0
votes0
answers39
viewsHow to know the total of real estate and the total of photos in an SQL with two INNER JOIN?
I have the following SQL INNER JOIN and would like to know how I can get the total of REAL ESTATE and also the total of PHOTOS, I have already used COUNT(immovel.id) AS TOTAL to know the total of…
-
0
votes1
answer199
viewsQuery does not return results in PHP
There is a query in my PHP where you search the email list and return to PHP, however, it is not returning any results. The PHP Code looks like this: <?php session_start("admin");…
-
0
votes1
answer790
viewsSUM within SUM Entity Framework performance
I made a query with Entity framework and I’m having problems with performance. public static Decimal ValorPrevisto(this ClinicaModel clinica) { return clinica.Contratos.Sum(c =>…
-
0
votes2
answers539
viewsReturn records Timestamp() field
I have a table called interessados, in it have int_data this field is timestamp(), I have 5 records with the following dates: 2016-09-01 10:15:00 2016-09-01 10:50:00 2016-09-01 18:35:00 2016-09-01…
sqlasked 8 years, 2 months ago Sr. André Baill 6,946 -
0
votes1
answer972
viewsHow to handle database working with Docker?
I started working with docker recently and there is a doubt and in a preparation for an environment wordpress lamp , I stumbled upon climbing my bank and my files . The idea was to leave everything…
-
0
votes3
answers672
viewsCondition in Where SQL Server
I have a SELECT with several LEFT JOIN, but I need to consider all of these LEFT JOIN in some conditions, already in another condition I need to disregard a JOIN done. As an example below: SELECT *…
-
0
votes2
answers47
viewsFind data not registered in postgres
I have field records that have fields with years and months like this: id mes ano ---------- 1 1 2005 ---------- 2 2 2005 ---------- 3 4 2005 ---------- 4 5 2006 ---------- My doubt is: It is…
-
0
votes1
answer50
viewsDoubt about SQL in PHP
I am currently carrying out a work that needs to access the database, and I had a lot of difficulty in some darlings, among them the query of UPDATE. But after much searching I found a solution and…