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
-
2
votes3
answers113
viewsSelect two tables
Good afternoon! Please I’m not managing to make a select I have two tables in the bank (campaign and campanha_clicks) I need to select only the results with the table type=2 (CAMPAIGN) and at the…
-
2
votes1
answer35
viewsConcatenate values of a Database into SQL
Using SQL I am making a record that I will give a SELECT in a database in which some records comes duplicated which is structured as follows with the same adhesion ex:…
sqlasked 5 years, 6 months ago igor fortaleza 89 -
2
votes2
answers891
viewsDatabase modeling of a banknote system
I need to create a database for a banknote system, but I’m terrible with data modeling. I did the modeling but I don’t know if it’s correct. The fields are not yet definitive, I just want to know if…
-
2
votes1
answer37
viewsSQL, Relation between SQL tables
My question is about the list of tables in sql. In an academy system I want to make a relationship between the student and his training record. I made a relationship from one to one, because each…
-
2
votes2
answers191
viewsCOUNT() query does not work
The purpose of the query is to list, within a user-defined period, all states and their total number of independent quotes if zero. Customers must be active (status 30) and have city id number…
-
2
votes1
answer114
viewsRelating distinct foreign keys in a column?
Hello, I am creating a table to register materials or services that depend on two other tables to form your cost center (Foreign key), depending on the type of registration. If I’m going to register…
-
2
votes0
answers54
viewsSQL Group BY SELECT CASE
I have the query below to select some records and a Boolean "Isbranch" that indicates whether to select the branch or not. The problem is that when it is false the results are not getting grouped.…
-
2
votes2
answers75
viewsLooking for a group of duplicate records
I have the table below: declare @order table (idOrder int, altcode varchar(17) ) insert into @order values (1,'11111111111') insert into @order values (1,'22222222222') insert into @order values…
-
2
votes1
answer342
views -
2
votes1
answer91
viewsSQL query where the last 2 digits of WHERE should be ignored
I’ll try to get to the point. I got the following SELECT: SELECT * FROM "Inverter" WHERE "InstallationUUID" = '0D013C023900-15-0B4B00' AND "CreatedTime_Key" > 20170718000000 AND "CreatedTime_Key"…
-
2
votes1
answer222
viewsHow to add an object inside stdClass() and print the json
How do I add a variable or object within a json. It is thus printing my json: {"Registros":[{"RegistroOperacaoID":"39","Tipo":"11","DataOperacao":"2019-03-27…
-
2
votes1
answer133
viewsWherein problem using array
I have a system where I need to list some employees. This listing will depend on the supervisor’s department code. Ex: If the supervisor is from department 206, he can access all data from the…
-
2
votes1
answer83
viewsWhat would be the ideal unique natural key associated with a person?
I’m developing a system whose one of the tables represents people. Of course, the most accurate document to represent only one person is CPF. However, the system provides for the possibility that…
-
2
votes1
answer1417
viewsMount SQL query in Python3 from data in a dictionary
I’m trying to format a query and leave it this way: INSERT INTO users('username', 'password') VALUES ('meuusuario', 'minhasenha') But you’re returning me with []: INSERT INTO users(['username',…
-
2
votes1
answer289
viewsForeign key with UNIQUE
What happens if I put one foreign key as UNIQUE in a table? I tested that possibility but maybe I misunderstood, if we apply a UNIQUE in a foreign key and insert the wrong value in this table, the…
-
2
votes1
answer39
viewsBugando Bank Field with Thousand values
Guys, I know it’s a very basic question, but how do I make a field of my bank accept values where these are values like 1000+ and also come as decimals. I will show an example below in the value of:…
-
2
votes1
answer74
viewsFilter using combobox
I’m trying to make some filters using combobox, these filters correspond to the year and month pulled from a date. For example: When selecting the year 2019 and the month 01 all results for the…
-
2
votes1
answer60
viewsError with another bank’s Foreign key
I’m trying to put Foreign key related to tables from another database (I’m performing tests and sometimes I need to delete the main database). However it presents the following errors: Message 1763,…
-
2
votes2
answers103
viewsInsert value in Table Y for all existing Table X Ids
I have a table called CONTAS with a column account_id. I have another table called PREMIO with columns account_id, id_premio and itemqtd I wanted a command where I inserted the id_premio and itemqtd…
-
2
votes1
answer60
viewsView linked ID of a duplicate mysql record
I wonder if it is possible to show duplicate records and which id that they are duplicated. Table Example: I would like to display the duplicate names, but let him also inform me id along. I made…
-
2
votes2
answers203
viewsQuery data with mask - SQL Server
I have the following structure: http://sqlfiddle.com/#! 9/29027c4/1 CREATE TABLE PATRIMONIO ( NUM_PATRIMONIO VARCHAR(100), DESCRICAO_PATRIMONIO VARCHAR(100) ); INSERT INTO PATRIMONIO VALUES…
sqlasked 5 years, 2 months ago Layla Comparin 553 -
2
votes1
answer60
viewsHelp in SQL query for LINQ
I have a problem/difficulty, I have this following SQL query that I need to transform it into LINQ, but I am having problems in LINQ COUNT(). select m.id_marca, m.ds_marca,…
-
2
votes1
answer788
viewsGroup different values of days per month (Oracle)
I have an appointment to do, it seems simple, but I’m not able to think of a way to make it work I have to select different values per day and group them by month... For example, a patient goes…
-
2
votes3
answers454
viewsReplace Sql in the middle of the text
SQL Server Database , Column is a Varchar(9) . And I need to fix this data because I need to filter only by people over 50 years old and that way I’m not getting , more in case someone knows a…
-
2
votes2
answers552
viewsHow to insert a midnight datetime into mysql?
I’m using the Laravel Framework 5.8, I am trying to register a record in the database where I need to set in API some dates. Although they are CURRENT_TIMESTAMP, i also need to be able to enter a…
-
2
votes1
answer72
viewsHow to make a select taking into account if the record exists, if it does not exist return null or empty
I have a code that returns the activities that have been completed within a 12 month period. SELECT empresas, tipo_atividade, CASE WHEN (SUM(CASE WHEN MONTH(dt_vencimento) = 1 THEN 1 ELSE 0 END))…
-
2
votes1
answer86
viewsSELECT returns nothing when I put a WHERE clause
When I run the following sql command I get an empty return, even if I indicate an id that is present in some rows of the table to be searched SELECT e.data_request, e.id_exchange, e.data_exchange,…
-
2
votes3
answers127
viewsHow to get dates with X days interval?
I have a field data in a table. And every day I will search: SELECT * FROM table WHERE DATE_ADD( data, INTERVAL 7 DAY ) = CURDATE( ) That is, if the date of the table + 7 days is equal to today.…
-
2
votes5
answers79
viewsSQL using two tables
I need to select all records from the table solicitation where all the table records tasks that have in the column id_solicitation the id concerning that request, and date of completion are…
-
2
votes1
answer100
viewsError when adding foreign key in SQL table
Hello, I am trying to add a foreign key to an already created table and it gives the following error: Error(s), Warning(s): Incorrect syntax near the keyword 'Foreign'. I tried some modifications in…
-
2
votes0
answers59
viewsLogin system php
Hello, I am creating a site with login system in php, and I have the following problem, When I enter Login it does not check in the database if the information exists. I wish I knew what mistake I’m…
-
2
votes1
answer58
viewsDoubt about SQL - Group by (beginner)
I have two tables, one with the names of doctors and the other with the classifications of the appointments and I want to list the doctors and the quantities of appointments based on the…
-
2
votes1
answer45
viewsGet list elements after Insert
I have an empty list that will be fed by inputs. In case, how do I insert the data stored in this list into a database (SQL Server)? I tried this way but it didn’t work. import pyodbc, datetime…
-
2
votes2
answers48
viewsSQL showing records if they only meet different conditions than usual
I have a slightly different situation, tried different conditions but none brought the desired result. My need is this: I have a base containing authors of books and their respective works. I need…
-
2
votes2
answers103
viewsHow to search multiple data in mysql without losing performance
I have a table called "readings" where my search returns 10 thousand results for the equipmentid = 1 SELECT id, result, date FROM readings WHERE equipamentid = 1; for each returned result I need to…
-
2
votes3
answers95
viewsHow do I leave the primary and foreign key of a table with the NOT NULL Constraint in Postgresql?
I am creating primary and foreign keys with the NOT NULL Constraint in Postgresql, only the way I am doing this is going in the properties in the table and manually setting the keys as NOT NULL, I…
-
2
votes1
answer201
viewsSELECT MAX With more than three columns
I have the following table: jobname aplicacao start end tempo_de_execucao PROCESSO_C APLICACAO_C 3/4/2020 3:01 3/4/2020 5:39 2:37:26 PROCESSO_E APLICACAO_D 3/4/2020 6:00 3/4/2020 6:41 0:40:51…
-
2
votes0
answers69
viewsDoubt mysql SELECT
Guys I’m having a question, follow the SELECT down below: SELECT o.matricula, v.cd_operador, o.hora, c.nm_nome, COALESCE(SUM(o.quantidade), 0) AS sacolax, v.sas03 AS sas03,…
-
2
votes1
answer367
viewsHow can I see the SQL generated by Entity Framework Core?
I am using version 3.1 of EF Core, and I am trying to see the SQL generated from this code: var query = Db.Set<Area>() .Include(i => i.Extratos) .Include(i => i.Coordenadas) .Where(x…
-
2
votes1
answer162
viewsSELECT Recursive (SQL)
Good afternoon! Guys I’m having the following difficulty: Imagine that I have a list of several Customers, and each customer has a Rating Group ( the Rating Group can be repeated for some…
-
2
votes2
answers109
viewsCONSULT DATA FROM A FOREIGN KEY TABLE
I have 3 tables in a database, one houses customer data, other products and one sales, containing foreign table id key products and customers. I need to make a query that shows the purchases made by…
-
2
votes1
answer29
viewsUsing case to match fields
I have the following structure --------------------------------------- |DT_Ven | VLR_CONTA|DT_QUI | VLR_QUI| |-------------------------------------- |30/07/20| 84,00|NULL | 84,00| |03/08/20|…
-
2
votes1
answer54
viewsCan I rename an attribute by creating a table from a type?
Following the Object-Relational model, I want to create the tables or_medico and or_atendente derived from t_funcionario that I created. Below follows the structure of type: DROP TYPE t_funcionario…
-
2
votes2
answers65
viewsList data from Procedure sqlsrv PHP
Good morning, someone with experience in PHP and microsoft sqlsrv drive ? I found it difficult to display data from a Procedure in SQL SERVER with the "Microsoft sqlsrv driver". Something strange is…
-
2
votes1
answer42
viewsHow to duplicate a table by changing string values to decimal
Good afternoon, you guys. I am learning SQL and I set out to import a table . csv from the central bank to apply my knowledge. The table consists of four columns: date entered | name of the currency…
-
2
votes0
answers36
viewsTrigger after Insert SQLITE
Hello, I have a table of activities (for Deposit or Withdrawal of a piggy bank app) is inserted ID (PK automatica), value (double) Day (Text) type (can be 0 - for deposits / 1 - withdrawals) and…
-
2
votes1
answer53
viewsDelete repeated lines
Good morning, I have a table "Patient" with the columns (NO, Event, Glycozyme, Name, Glycemia, Date, Reading), which is the best way to delete all the repeated lines? Looking on the internet I tried…
-
2
votes1
answer52
viewsMysql, Sum accumulated values by date and ID
Good afternoon, I’m having a problem to get a relatively common result, I’ve seen some materials talking about but none applied to my specific need. I need the cumulative total of each release,…
-
2
votes1
answer24
viewsHow to return the last record of each sale
How to return the last record of each sale considering the max(date)? +---------+--------------------+---------------+ |venda |Data |id | +---------+--------------------+---------------| |0000001…
-
2
votes2
answers131
viewsInsert data with pymysql into a mysql database error. How to resolve?
seqteste.txt or List: >gb:KX262887|Organism:Zika virus|Strain Name:103451|Segment:null|Subtype:Asian|Host:Human GTTGTTGATCTGTGTGAATCAGACTGCGACAGTTCGAGTTTGAAGCGAAAGCTAGCAACAGTATCAACAG…