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.
54
questions
0
votes
0
answers
4
views
Azure VM: SSRS data driven subscription intermittent error
I have Azure VM database which I use as a source for my DB Source. My SSRS server generates Data Driven report emails out of this db and always have intermittent problems while running my process (...
0
votes
0
answers
12
views
Efficient SQL full data retrieval combining JOINs and WHERE
I have a quite complex data model in my current project's database and I am wondering if there is a better/more efficient way of getting all data, after applying some filters, in a single efficient ...
1
vote
2
answers
30
views
Find records as And in MYSQL
I want find Students id that , must have (professorId = 3 And courseId = 4) And (professorId = 3 And courseId = 2) And (professorId = 5 And courseId = 8).
sometime these parenthesis is one or more ...
1
vote
0
answers
37
views
SQL Inner join with where clause works fast with one condition, but not when activeFlag is added
I have a query like
select C.customerId, C.firstName, C.LastName, R.IsActive from
Customer as C
Inner join Rider as R ON R.customerId = C.customerid
where R.rideid = 'xyz' and
R.rideareacode = 'abc' ...
-3
votes
0
answers
22
views
Asking for help converting SQL query to EF Core [closed]
I have a working program that uses SQL queries to collect data. I'm working on converting it to EF Core 8.
I found an online convert but the result will not compile in my C# project. Can someone ...
0
votes
2
answers
39
views
Joining tables with different date formats (Literal does not match format string)
I'm trying to join two Oracle tables (basically to pull in a daily rate against the date in another table), but the table I'm pulling the date from has the timestamp in it. I'm seeing a lot of ...
0
votes
1
answer
24
views
Accessing deeply nested fields using DuckDB SQL
I have some deeply nested data from a json file and I'm trying to load it into DuckDB:
"events": [
{
"id": "401638586",
"uid": "s:40~l:41~...
0
votes
0
answers
52
views
Get the no.of records Inserted in last 10 days
In my table I didn't have primary key and forgot to add timestamp column. Now I would need to find the records with date time of insertion in last 10 days. Is there a way to find this? If yes then how?...
0
votes
1
answer
32
views
How to query for an amount when it changes values base on a record (account#)
I am trying to query for an amount when it changes base on a record. For example the below table.
I want to query for the rows with a (****). I want to know whenever the balance changes for each acct. ...
0
votes
1
answer
17
views
How to add permission to custom role in postgres to create index
I am currently creating a role for a particular database using the below sql script executed as master user (postgres).
CREATE USER customrole WITH PASSWORD 'mypassword';
-- removed CREATE ...
0
votes
1
answer
17
views
How can I rank after filtering inside a window function?
I have a huge BigQuery table "taskperformance" that attributes tasks to sales (ordered in this example for easier
understanding):
sale_id
sale_timestamp
task_id
task_timestamp
is_same_store
...
-3
votes
0
answers
52
views
Why am I getting the wrong value or NULL after doing left joins? [closed]
I have a table called Persons with an ID column. I have another table called Cases which has an ID, another PersonID, and the date that the case was made. I have a third table called PersonsCases, ...
-1
votes
0
answers
13
views
Best practices for improved performance for data retrieval interaction , sql or graphql within flask
Let's say I have three products. one is my database, accessible through SQL , a GraphQL server, and a webApp GUI to access the information of interest.
As an example i will say that people around me ...
-1
votes
0
answers
50
views
Improve performance or change query so it can be an indexed view
We have this query in a non-indexed view in SQL Server 2022.
It's used everywhere and I'm trying to improve the performance. A lot of queries we use elsewhere join to it.
My thought was whether there'...
-1
votes
0
answers
40
views
Stored procedure data export double quotes
I created a previous post about double quotes in a query which gave me a good answer but unfortunately I'd have not posted the full stored procedure. I'm having some trouble getting double quotes to ...
-4
votes
0
answers
32
views
Validating rules [closed]
I've a table data:ORG ER |ACT | BUD N |ACT N_1
I identify the cases where I need to identify the ORG ER which will be rejected and I need to insert it in a table of reject.
Here the rule 1 that ...
0
votes
2
answers
25
views
Query the lowest sub-value where the main value is grouped
I am trying to create a basis for a list of products in an MS Access Query. The basis must later be used in a form where the products are visualized with only one of the many images associated with ...
0
votes
1
answer
41
views
Get all hierarchy in SQL Server
I have a table like this:
ID_employee
ID_Manager
1
1
2
1
3
1
4
2
5
3
6
5
7
5
8
5
(1 is a boss)
What I would like is a result like:
ID_employee
ID_Manager
8
5
8
3
8
1
7
5
7
3
7
1
6
5
...
0
votes
1
answer
27
views
Deduplication based on other dataframe columns
I have pyspark df1 as
+----+
|name|
+----+
| A|
| B|
| C|
| D|
+----+
and df2 as
+------+------+
|name_a|name_b|
+------+------+
| A| B|
| B| A|
| C| A|
| A| C|...
1
vote
1
answer
24
views
How to convert a row from a table to ENUM in JOOQ?
JOOQ does not convert rows from a table to enum
I tried different conversion methods, but they either didn't do anything, or they displayed errors, I tried to add codegen jooq, but I can't do it, I ...
0
votes
0
answers
13
views
Navicat 16 Backup Error: 'column d.datlastsysoid does not exist' for Postgres 15.4 Database [duplicate]
I am using Navicat 16 to back up my remote PostgreSQL database, which is running version 15.4. However, during the backup process, I encounter an error that reads:
[ERR] ERROR: column d.datlastsysoid ...
1
vote
1
answer
59
views
INSERT rows that were missing for the UPDATE
I want to write a query that, if I was using variables, would look something like (pseudocode)
records = SELECT * FROM table_1 WHERE id = x
numberOfRowsUpdated = UPDATE table_2 SET column_1 = y WHERE ...
0
votes
2
answers
42
views
Select user's high score for each lesson from one table based upon lesson ids in another table
I have a site that has multiple courses and each course has multiple lessons. I would like to select the highest score per LESSON for a given user_id and course_id ordered by lesson_order.
TABLE ...
-1
votes
0
answers
45
views
Session variable into a prepared statement [closed]
When I submit a form, I would like the Session variable user_id to carry through to my prepared statements so it can be inserted into my table.
Code of dev.inc.php (following comments...)
<?php
if(...
-2
votes
0
answers
22
views
insert in to target table and avoid the rows with same set of column value from source to target [duplicate]
-- Create a temporary table with sample data
CREATE TEMPORARY TABLE temp_student (
roll_no INT,
name VARCHAR(50)
);
-- Insert some sample records into the temporary table
INSERT INTO ...
0
votes
2
answers
47
views
Is there any method to convert a varchar with specific format into time in Oracle SQL?
I have a table with three columns, one of the columns ateststatus_date has the following format: e.g:
28-MAY-24 11.57.20.000000 PM
and it's defined as varchar(2). I used To_date() and ...
-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
55
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
43
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
46
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 ...