Questions tagged [sql]

Structured Query Language is a language for interacting with relational databases. Read the tag wiki's guidelines for requesting SQL reviews: 1) Provide context, 2) Include the schema, 3) If asking about performance, include indexes and the output of EXPLAIN SELECT.

Filter by
Sorted by
Tagged with
0
votes
0answers
6 views

Complex reporting query suggestion needed for different approach as per latest Tsql format

We have recently migrated from SQL Server 2008 R2 to SQL Server 2017 web edition. I am not a SQL developer but enthuses to learn. Since many of our scrips are of old SQL format, I am searching for ...
1
vote
1answer
45 views

Calculate course module credits from individual assessment scores

I'm currently working on a grade calculator for a university (professionally), and I am wondering if anyone can suggest an improvement to the following query? Here is my database: The query returns ...
0
votes
0answers
21 views

MTG Metagame Schema

So there's another question about storing information about a trading card game, but in my situation I have to store not only raw tournament information but a lot of statistics I've extracted from it: ...
3
votes
1answer
80 views

Preventing sql injection in php (pdo) and mysql

I am a begginer, and I'm trying to secure a sign-login system on my website. Is my code good/enough to prevent sql injection? THIS IS THE SIGN FILES This is the index.php that takes user input: ...
1
vote
0answers
21 views

Django Models for an ESL school

I am working on building a management interface for an ESL (English as a Second Language) institute, basically it is a language school where people learn English. I have prepared my models for each ...
2
votes
0answers
14 views

Getting new vs. returning customers in Postgres

I have this work task, to write a SQL query that would show how many of the active customers are new (= do not have prior transactions) as opposed to returning per a given period. There is nothing ...
-3
votes
1answer
41 views

Form a flat indexed array from a multidimensional result set [closed]

I want make my looped data into one flat array without associative keys. I have solved it with my code, but I think it is so crowded and not simple. This my code: ...
-1
votes
1answer
29 views

SQL JOIN QUERY with more than one items in common: Find the franchise pairs that operate together in more than one location [closed]

I have a table called dfmt that lists the location, revenue and franchise. I want to find the franchise pairs that operate together in more than one location. So far, I have a query that finds the ...
1
vote
1answer
34 views

Multiple functions connected to SQL

I have created a thread before regarding the similar code review I had before Previous code review - I have updated a small piece of advice I got from previous answer and I did realized I have ...
-2
votes
1answer
185 views

Query builder class pdo,sql

Need some advices to create class that handles sql query operations with given array (having full control of the array and obtaining record information). My code works properly (it is just example), ...
1
vote
0answers
41 views
0
votes
0answers
45 views

.net core console app read from external API and write into a database

I have a .net core console app that gets some data from an external API and inserts it into a SQL database table. It is working as expected but I wonder if you guys have any suggestions to make it ...
0
votes
0answers
28 views

how to rewrite sql query with subquery to find max element without using limit?

the question is here Return the name of the category that has the most films. There are 2 databases - film_category: ...
1
vote
3answers
73 views

Delete companies with the least number of flights

I have solved the task of Delete the companies that made the least number of flights. the visual table diagram is here. The exercise is here This is my source code -it's "arrow antipattern"...
5
votes
2answers
113 views

PHP: Simple SQL query builder

I've been lucky enough to get my first job as a junior PHP developer. I am concerned I'm not good enough. I would like to brush up on my coding skills and get as much constructive criticism as I can. ...
0
votes
0answers
6 views

View returning results from multiple tables

I have a DB2 SQL view created with below statement: The problem I am facing is kind of strange. When we do a select * on this view, it runs slow for the first few times every new session. But then ...
4
votes
1answer
163 views

Calculating the Percentage of a Pair Occurring Across a Lot of Lists

I'm looking for a way to speed this code up. It took about 4.5 hours to run on ~20k decks. I'm open to restructuring my SQL query, but feel adjusting the python would be more effective. The goal of ...
0
votes
1answer
26 views

Shortening Oracle SQL containing several unions

I believe the provided code can be rewritten shorter. Now one block is basically copy-pasted. In reality I have 6 such blocks. This would be the data: ...
-1
votes
2answers
99 views

My Script Inserts users into a database and hashes the password, I need to know how to prevent SQL injection with Procedural-Oriented MySQLi [closed]

My script works but I just want to know how I can protect myself from SQL injection with Procedural Oriented MySQLi. Most of the tutorials are about Object-Oriented MySQLi and I'm not familiar with it ...
2
votes
1answer
66 views

Reducing Inventory Quantity When Order Is Being Processed

I've got a method which removes quantity from inventory when an order is completed. If there is not enough inventory quantity available, the order completion fails and the sql transaction is rolled ...
1
vote
1answer
20 views

Avoding CT and other sins?

I'm a SQL learner. In answering the question* For the region with the largest sales total_amt_usd, how many total orders were placed? for the following schema: (I am unsure of the dialect is but I ...
0
votes
0answers
37 views

Simple Todo CLI APP in Python with SQLalchemy

I wanted to ask you a favor. I am recruiting for the position of Junior Python Developer (my first try in IT) and I got a task to create a script to manage the task list. https://github.com/Lok3rs/...
5
votes
1answer
177 views

Basic schemas for database and tables creation, bulk import from .csv and basic queries

The following SQL code serves the purpose of assessing basic SQL Server literacy. I am creating database and tables schemas, inserting data from .csv files. Constructing 8 simple queries as answers to ...
3
votes
2answers
77 views

Keeping only maximum date rows in a group

The following SQL code keeps only the MAX(date) rows with the same id and question values. I would like to know if there is a simpler/ shorter syntax returning the same result. ...
1
vote
1answer
39 views

Creating SQL Table from a Go Struct

I have been building an API in Go, which I want to link to a Postgres SQL table. I have always used NoSQL previously but thought ...
2
votes
1answer
62 views

Managing a store in PostgreSQL

I have been trying to improve python combined with Postgres. At this moment im only sending two values to database which are etc: ...
4
votes
1answer
180 views

Is my structure of program readable?

Just looking for reviews to improve my coding and my structure of C#. It feels I probably have some unnecessary code that is not needed, been following some YouTube videos to accomplish some tasks. ...
2
votes
2answers
79 views

Select non-task workorders, but include the costs of the tasks

IBM's Maximo Asset Management platform has a WORKORDER table (265 columns). Details: The WORKORDER table contains two different kinds of rows: WO records (istask = 0) Task records (istask = 1). The ...
7
votes
3answers
807 views

Reorganizing unorthodox PHP phone book project

I've been learning PHP and I've created a phone book webpage as an exercise. I am satisfied with the way it works -- it seems to handle all possible input cases correctly, and the interface feels nice ...
2
votes
0answers
18 views

Postgresql - query returns different results on 2 copies of same database [closed]

I have the following postgresql query that was created for use in a production database to return a daily recap of counts. This query runs and returns correct results in the "staging"/test ...
1
vote
1answer
62 views

Retrieve data from two different rows in a single SQL query?

I've a table with the following data and I need to find the number of minutes between two jobs (Say A and C). The following query works but wondering, if there is a simpler way to achieve the same. <...
6
votes
1answer
67 views

Delete Entry from SQL-Table and confirm the deletion to a CommandSender in a spigot plugin

I'm working on a spigot plugin, that deals with messages to from players on a server to the admin's. It's the same plugin this question relates to: SQL structure to save coordinates for spigot plugin ....
6
votes
1answer
63 views

SQL structure to save coordinates for spigot plugin

I'm writing a spigot plugin where I give the user the possibility to send a message to the admins of the server. One of the requirements is that the coordinates of the player are stored, when the ...
1
vote
0answers
113 views

Golang DB connection with AWS SSM Parameters and context

I'm working on setting up an app backend that's deployed automatically using infrastructure-as-code and a ci/cd pipeline. As a result of that I need the app server to gather DB credentials ...
2
votes
0answers
21 views

wordpress slow query shown in query monitor

I have a slow query on a wordpress site. How can I rewrite this to make it faster? I'm not having much luck. The query takes about 0.900 seconds I have both the query and the explain below, my goal is ...
2
votes
1answer
26 views

MS Access query complexity on finding duplicates

I have a list of names and ID's, with many multiplication (it's a payroll list). I'd like to see those ID's and names where the name changed somewhen. Input: id1 name 1 Josephine Baker 2 Norma ...
3
votes
0answers
89 views

PowerShell Script to get data from Third Party API and insert into database

I have created a PowerShell script that will call a REST API and then for each node returned, add the data into a database table. This particular endpoint only returns ~600 records worth of data, ...
0
votes
0answers
46 views

SSIS and multiple API calls, a better way? [closed]

I am looking for some guidance on my solution as I am convinced there must be a better way. The below is my setup... SSIS Package API 1 - This calculates invoice totals and payments API 2 - This takes ...
1
vote
1answer
31 views

Possible improvement on join query

I have the following query which retrieve all those who have ordered a book_id n°10 and but never ordered the book with id n°1. http://sqlfiddle.com/#!9/1bb9e8/44 ...
2
votes
1answer
80 views

How to speed up a treeview population in Access?

I have the following function that causes a significant visual jittering and lag in my access database - This is a treeview selection based on data in a table (tblDATA) with the fields: Object | ...
3
votes
2answers
111 views

How to get the median value faster

Using Excel, I have one sheet ("db") with data extracted from MES. I have to analyze this data and I need: Articolo, Fase, Tipo Confezione, TURNO, Macchina, avg and median. I searched ...
3
votes
1answer
63 views

all appointment based on interval distance

Currently with a given Date and an Interval in Day, I can calculate all of the appointment in the future. for example if you are ...
1
vote
0answers
24 views

Microservice unit testing database script insert Error - H2 [closed]

For unit testing my ProductList service, I tried run a script to insert some data and then try to get this data and compare the list size. But my database insert script is not running and returns null....
2
votes
2answers
131 views

Secure file upload for PDF only

I am trying to create a secure file upload using PHP 7+ where I only allow PDF files. I found a lot of posts on this topic on different websites but couldn't find a complete solution that ensures that ...
2
votes
1answer
60 views

MYSQL select count two table left join

I have two table. I want count how many times a value is in other table. So the codice from table "sorgente" is different in table contatore, because I have the suffix 'BRANO-' before the ...
7
votes
1answer
127 views

VBA-Sync code feedback

I was hoping to get some input on a class module I'm designing to abstract away the boilerplate of utilizing asynchronous queries in VBA. cQueryable supports both synchronous and asynchronous queries. ...
3
votes
1answer
106 views

Any ideas how do I prettify this SQL query?

This question is abut coding style. I'd like to see how would you improve this code look considering readability as well. Feel free to upvote others solutions you find good. #1 Initial version: ...
3
votes
0answers
270 views

Login function with python and SQLite

I'm a new programmer who is currently working on a personal project. It is supposed to be a login program which stores user data in a SQLite database. I was wondering if anyone could look at my code ...
2
votes
0answers
49 views

Using R to Dynamically Query Database Using SQL Template

Purpose of Code The purpose of the main function (get_player_penalties()) is to: Generate simple SQL statements from user input and a template Query a database ...
2
votes
1answer
64 views

Login system in PHP using AJAX

I am beginning the cycle of creating my role based access control into my framework. I now want to log the user into my application and my _user table looks like this: ...

1
2 3 4 5
29