Questions tagged [sql]
Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.
58
questions
-2
votes
1
answer
32
views
Select multiple column(Created Date) with duplicate unique ID in a single row
Having records like this
ID
Created Date
1
2024-07-23 00:25:17.113
1
2024-07-23 00:31:17.113
2
2024-07-23 00:22:17.113
2
2024-07-23 00:29:17.113
enter image description here
Expectation
ID
...
0
votes
1
answer
56
views
Query between two dates gives incorrect results in SQL Server? [closed]
Im trying:
SELECT *
FROM database a
WHERE Applicant_End_date >= '2024-01-01'
AND Applicant_Start_date <= '2024-06-30';
Results:
Applicant_End_date shows results starting at 2024-01-01 like:
...
0
votes
0
answers
44
views
How to Use a Single INSERT INTO Statement for Multiple Rows in Python?
I’m currently working on a Discord Python bot where I loop through a list of ForumTags and generate an INSERT INTO SQL statement for each object to insert data into a MySQL database.
However, I want ...
1
vote
3
answers
48
views
Converting char to date and pulling past two years data
I need to pull data from tables with millions of rows and limit it to just the past two years. I am working on developing a SQL statement to enter into Power BI to limit what it pulls. Obviously I am ...
0
votes
1
answer
30
views
How do I query rows of only the max value record of unique IDs within a table?
I have a table of data with application records where I would like to see only the latest entry submitted. Some unique_ids have 1 application records, while other unique_ids have 15 records. If a ...
0
votes
2
answers
48
views
MergingTwo SQL Queries Select and Count in Single statement
I am Working on project, where I am using two queries to get the result i wanted to process.
Query 1
SELECT MID FROM PMS.MACHINE WHERE STATUS=1 AND MID !=0;
Query 2
SELECT MID,COUNT(STATUS) AS QUEUE
...
-1
votes
0
answers
45
views
SQL query to return the MAX(CreateDate) from tables that are returned in the initial result set?
Working on a SQL Server Management Studio query. The goal is to return the MAX(CreateDate) and table names from a query that returns a set of values from a column called WhenSQL. Each table has its ...
0
votes
1
answer
47
views
Selecting Rows By Specific Column Data in PostgreSQL
I'm trying to build a recipe finder app (PERN stack) like SuperCook but I ran into some problems with my postgres table.
Short description of the desired result. I'd like the user to select some ...
-1
votes
1
answer
58
views
SQL JOIN to the same table explanation
I am refactoring some code that was written by another person that is no longer around. In this query a MAX(Date) is being selected, but then joined to they same table via MAX(Locator). The locator is ...
0
votes
1
answer
43
views
How to update a SQL column in a stored procedure if the column was added?
I have a stored procedure where I select records from a table and I added a column for a flag (ReviewedFlag).
If I need to update this field how can I do it outside of the stored procedure? I need to ...
0
votes
1
answer
47
views
SQL using ROWS BETWEEN to aggregate 12 months, nulls included?
I'm currently working with a table with the following columns:
Supplier
itemnumber
invoice_year_numerical
invoice_month_numerical
invoice date
invoice amount
invoice qty
I'm using SUM(invoice amount)...
0
votes
3
answers
36
views
Keep the longest record in a column for multiple entries
I am trying to filter in a query records that are returning multiple entries. I want to keep the longest records as it correlates to the furthest nested path. Example:
The simplified query:
SELECT ...
0
votes
1
answer
22
views
ClickHouse - creating time table
I'm trying to create a time table on the ClickHouse. This is a simple table consisting of 4 fields.
The first field shows the date + time in one minute increments ranging from 00:00:00 to 23:59:00.
...
0
votes
1
answer
67
views
WITH (NOLOCK) /SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED on stagnant data [duplicate]
I will prefix this by saying I may be misunderstanding / misinterpreting something here!
Our IT dept requests we update queries / stored procedures to use NO LOCK. I need to add that to every stored ...
0
votes
2
answers
38
views
Fill value from previous date if current date is not availables
I have two tables - sales and currency_rate. I want to fill col CurrRate to each transaction line from Sales based on the the month as from table sales col [Date] and table currency_rate col ...