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
votes0
answers341
viewsSQL using Join with subquery
I have the following code: select FACAV_CDMATCOOP,CCCCO_NOCOOPERAD,FACLA_ORIDAVIAR FACLA_QTPESOLOTE, FACLA_QTENTREG1, FACAV_ORCDAVIAR, FACLA_NRLOTE, FACLA_DTYALOJA, FATCR_QTPESOMED from FACAV F…
-
1
votes1
answer263
viewsQuery "or" and "and" in Laravel
Could someone help me? I need to do this query on the Laravel: SELECT * FROM materiais where material like '%caneta%' or localização like '%armario%' or fornecedor like '%kalunga%' and setor =…
-
1
votes2
answers86
viewsPHP & SQL - How to get specific information from each user in a table
Hello, I’m having trouble collecting information from users of a database. In DB there are some users, and they are displayed in a table. My goal is that when the names are clicked, a Collapse…
-
1
votes0
answers200
viewsNullreferenceexception - Object Reference not set to an instance of an Object
A person is launching a proposal, and I found through the Iderro generated on the page that she is accessing this error below. But I can’t understand his motive, so help me?…
-
1
votes1
answer63
viewsValues of the IN clause as a parameter for in a column subselect
I need to pass all the values of a clause IN, for a subselect one-column. Ex: SELECT distinct 'Atendimentos' Tipo, to_char(A.DT_ATENDIMENTO, 'mm/yyyy') Competencia, pre.cd_prestador, se.cd_setor,…
-
1
votes0
answers88
viewsI’m unable to do INNER JOIN in cakephp
All right, guys? I’m using cakephp to make a system that interacts with some database data from a Wordpress site however every time I try to perform an Inner Join cake query shows me this error:…
-
1
votes2
answers122
viewsSQL-C# ~ Add Student if not in class
Good morning, I have the following code below: public void AdicionarAlunoTurma(Adicionar_Alunos aluno) { List<string> parametros = new List<string>(); StringBuilder query = new…
-
1
votes1
answer445
viewsDifficulty creating Function in oracle
I’m trying to create a function in the oracle, but I’m having a hard time creating her return. CREATE OR REPLACE function simple_function( state VARCHAR2, city_id NUMBER) RETURN VARCHAR2 IS ret…
-
1
votes2
answers343
viewsHow do I get the latest date by following a SQL filter?
I need to create a filter by following the following rule: GSM which is repeated, and which MOTIVO_ENVIO equal, and STATUS = 'ANOMALIA TEMPORÁRIA' import only the line that contains DATA_ALTERACAO…
-
1
votes0
answers1080
viewsPHP & SQL - A failed connection attempt - XAMPP
Hey, guys, here’s my problem. I own my machine with a Mysql localhost, there is a website that I created, however, when I try to connect the DB of the site with another machine that is not connected…
-
1
votes2
answers2648
viewsCreating a simple database with NOT EXISTS
Every time I create a DER(Entity-Relationship Diagram) in a database, and then type this diagram in the Entity-Relationship Model, to scan the created diagram and also to perform the insertion of…
-
1
votes1
answer102
viewsSelect in 2 tables
PHP PDO Mysql The question is the following, I have two tables, one calls groups and the other membro_groups, I will give a summary in the tables, I can take the groups and show how many users each…
-
1
votes2
answers127
viewsPrevent Insert or Update If date is in a Registered range
I am with the following doubt: I have the table: Escala Data_Atuacao_Inicial, Data_Atuacao_Final, tipo The guy can be 1 or 2 I want to create a Rigger to stop the Insert or update of this table, if…
-
1
votes1
answer79
views -
1
votes2
answers580
viewsLaravel - Select in multiple tables
My goal in the code is: - Create a filter option for the customer, where he will have the options to filter the product by: COLOR, GROUP, FEATURE AND MEASURES. My problem is: - Create the query that…
-
1
votes1
answer210
viewsDownload the VARBINARY image
I have images saved in an SQL database on varbinary, I would like to know how to bring it back in my application and download it to the machine in some format (.png, .jpg). I’m programming with…
-
1
votes1
answer107
viewsHow to select distinct from the Listagg function in the 12C database
Is there any 12c bank function you can use on listagg and does not bring repeated results? SELECT SUM(quantidade) quantidade, LISTAGG (mib.segment1, ' - ') WITHIN GROUP (ORDER BY ROWNUM) item,…
-
1
votes1
answer179
viewsTransform Sql command into LAMBDA
I’m learning a little about LAMBDA and tried to convert this query into LAMBDA, but I stopped. I have 2 classes: public class Voo { public string idVoo {get;set;} public DateTime dtVoo {get;set;}…
-
1
votes2
answers240
viewsHow to sort a table according to data from another table
I have two tables Table 1 create table tb1 ( cd_tb1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY ); Table 2 create table tb2 ( cd_tb2 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, cd_tb1 int, vl_avaliacao…
-
1
votes1
answer37
viewsControl the data that Mysql sends to Nodejs
I developed a Project that "clones" a proposal and its products, in addition to making some updates, but the return that this procedure returns to my Nodejs is not very useful to me. It is possible…
-
1
votes2
answers51
viewsHow to loop Mysql based on a query
I wonder if it is possible to create an event in the Mysql database, where every 5 minutes the database makes a query, where it returns all the order ids and based on each id I perform another query…
-
1
votes0
answers49
viewsinserting blank line on the seat and one with the right data
When I enter a data in the bank is always recorded a blank line and another with the data I put. I tried to reinstall the xampp but it didn’t work tested on another computer and it worked the…
-
1
votes1
answer4919
viewsComparing column values in dataframe pandas rows
Good afternoon. I am comparing two given frames, data frame 1 has an sql query and data frame 2 a mysql query I want to compare the two. When the DF 1 record is not in DF 2 I want to save the result…
-
1
votes1
answer83
viewsHow to list items per month in SQL Server
I need to be listed assets that have something scheduled for a period, in case they need to bring me by month, I’ll leave an example below: I have here a report where I bring an asset that returns…
-
1
votes2
answers594
viewsComparison of datetime using Laravel eloquent
Hello, I’m having problems using Laravel’s eloquent to create an SQL that meets the following demand: "return a query if there is a reservation made in a certain period of time"; Following the code…
-
1
votes3
answers340
viewsSort in SQL by prioritizing a specific field value
I have a large client table, and I need to select the following fields (sample data) id | id_ls | id_sistema_ls | nome | ativo ---------------------------------------- 1 | 1007 | 158849 | A | 0 2 |…
-
1
votes1
answer578
viewsInsert or update Posgresql via Python
Today I am using the following code to call via API and store my data in the Postgresql database: conn = psycopg2.connect("dbname='DBNAME' user='USER' host='HOST' password='PASSWORD'") insert =…
-
1
votes1
answer55
viewsHow to know which columns were modified in an UPDATE using TRIGGER?
Good afternoon, everyone. I am creating a TRIGGER AFTER UPDATE in a table in the BD, and I need to know which columns were changed (regardless of the value that was placed), and put the column names…
-
1
votes1
answer57
viewsPrint days of the month in the table
I am trying to create a report based on some tables of my bank, in this report, I need to pass during the month, on which day the operation was executed, so I need to print out every day of the…
-
1
votes1
answer226
viewsSQL query where WHERE has 2 options
I intend to make an SQL query where WHERE has 2 situations, example: SELECT * FROM products WHERE name = "%Explosion%" OR tag = "%Explosion%" In this consultation I would specify that, first the…
-
1
votes2
answers313
viewsCalculate the average of a field in a specific year within a period
I was studying queries in mysql using the Employees demo database (link), when I decided to do a search in the table salaries than would be a report of how much the company spent per year on wages.…
-
1
votes1
answer232
viewsProblem with Mysql Pool conections
I have this class I use to create the connection: class DbConnection { constructor() { this._con = undefined; this._pool = undefined; } _createPool( database , user, password ) { this._pool =…
-
1
votes2
answers74
viewsSQL query, count the amount of existing values of a Foreign Key for each corresponding Primary Key in 1 query
Example with 2 tables: table admin: columns: | id_admin | email | password | values: | 1 | ex@ex | 123 | | 2 | ex2@ex2 | 123 | table news: columns: | id_news | title | content | admin_id_admin |…
-
1
votes2
answers46
viewsHow to search for information in two different tables and return the ID of the table where the information is?
I have a code that could be of a natural person OR legal, and I have a table for each one (one for PF and another for PJ). I would like to find this user in one of the two tables and return your…
-
1
votes1
answer8888
viewsConcatenate columns in SQL SERVER
I need to concatenate 3 columns in a row using SQL Server, when I concatenate it returns this value: Would have to stay: Moura 105ah ground floor I’ve seen some examples on the internet, but I…
-
1
votes2
answers874
viewsJava: create Inner Join using criteria
I’m having a hard time finding good examples of how to create a query criteria using Inner Join. I created the query below that would be what I would like to do with the criteria. SELECT DISTINCT *…
-
1
votes1
answer43
viewsCompare tables and add result to row
I have two tables Table 1 N3_FILIAL | N3_CBASE | N3_ITEM | N3_CCDEPR 0N3_FILIAL | N3_CBASE | N3_ITEM | N3_CCONTAB | N3_CUSTBEM | N3_VORIG1 | N3_TXDEPR1 | N3_VRDACM1 0001 BENF000001 0001 12301020014…
-
1
votes0
answers61
viewsPDO works on localhost, but not on webservice
I made an app and it runs on localhost no problem at all. When I switched to hosting it simply does not read the SQL commands by PDO (it is enabled on php.ini). Connection seems to work fine,…
-
1
votes1
answer32
viewsMysql to SQL Sever
What would the following code look like MySQL in SQL Server 2008: desc `TABLE 2`; alter table `TABLE 2` add column `COLL 44` varchar(20) DEFAULT NULL; alter table `TABLE 2` add column `COLL 45`…
-
1
votes1
answer26
viewsI need help with this select
I have the following tables CAMPO1_FK 103 103 103 103 103 103 103 103 103 103 103 103 103 103 103 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108…
-
1
votes0
answers100
viewsUpdate Datagridview in c# via Trigger UPDATE SQL
Hello, I have the following question. I’m running a c# application with SQL Server database. I have a Datagridview where he is carried via Datatable, the information loaded is from people: Name,…
-
1
votes1
answer139
viewsRecover Select from Any Trigger
How can I get one back select of a trigger? Example: CREATE TABLE PESSOA2 ( ID INTEGER IDENTITY NOT NULL, NOME VARCHAR(250) ) CREATE TRIGGER SELECIONAR_NOME2 ON DBO.PESSOA2 AFTER UPDATE AS BEGIN…
-
1
votes1
answer103
viewsHow to pull data from a login
I need to pull the value of the 'level' that is in the bank because I am setting in some pages the question of access permission , only that I am not able to pull this data from the table . Can…
-
1
votes1
answer48
viewsSelect by period
I have this select. SELECT 5125 matricula, CONCAT(fum.nomeguerra, ' / ' , fuc.nomeguerra) nomeguerra, date_format(es.data, '%d/%m/%Y') as data, es.semana, es.horarios, es.linha FROM escala es LEFT…
-
1
votes1
answer340
viewsHow to insert a date into an SQL and Java tuple
I tried to insert a date into a tuple in SQL but I couldn’t, using the Calendar.getInstance() I can only get the current date, but I want to choose another date to add. public class Prova { private…
-
1
votes1
answer254
viewsSimple Quotes in Access
I have an Excel macro that reads the cell’s contents and saves it in an Access type database, when I try to insert a string that has simple quotes in the middle of the string and the following…
-
1
votes2
answers389
viewsSQL - Doubt Query Exists and Not Exists
Guys, I’m a bit of a beginner in SQL Database and I’m having a problem doing a query. I need a light, help because I’m not yet understanding how a query with a exist (has to be exists and exists…
-
1
votes0
answers45
viewsError naming check type Constraint
Hello, I’m sorry if my question is too trivial or if I’m missing some important information, but I’m trying to create a Constraint type check giving a specific name to it, but gives the following…
-
1
votes2
answers574
viewsCalculate Geometric Mean in SQL Query
Table Example Campo - Valor A - 30,21 B - 15,03 C - 5,06 B - 10,20 B - 12,89 C - 1,12 Geometric average calculation A = (30,21)^1/1 B = (15,03*10,20*12,89)^1/3 C = (5,06*1,12)^1/2 Results A = 30,21…
-
1
votes1
answer30
viewsSQL does not return any table data despite not giving errors
Good morning, I want that in the following code SQL returns from the database the values "id_Admin", "username_Admin", "password_Admin", but does not return anything despite not giving any errors.…