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
2
votes
3answers
3k views

Choice of tables for a project to handle attendance

I'm working on my students attendance system project. I have a list of students along with their ID (jntuno) and I need to create a database in MySQL for storing ...
-1
votes
2answers
25 views

Eliminate using same query twice when doing a right and left join between two subqueries on MSSQL [closed]

Aim : I have a history table, which maintains history on certain columns, denoted by hist_data. I get new data in a raw table (...
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 ...
-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: ...
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
79 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
13 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 ...
5
votes
1answer
45k views

Building a “LIKE” query in Yii2

This code makes an SQL query. The last andWhere() method adds a LIKE condition with one percentage sign at the right side of 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 ...
-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
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. ...
4
votes
1answer
119 views

Keeping track of voting

There is HTML that triggers the code below I want to disallow executing the script more than once per 24 hours. I wanted this script to store the last visit time in a table against the user ID in a ...
6
votes
1answer
158 views
1
vote
2answers
5k views

Selecting from a database into a DataGridView

I have a piece of code which grabs data from an SQL database and displays it in a DataGridView. This code works perfectly fine for me. It has been pointed out to me that the below code is bad ...
-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), ...
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 ...
3
votes
1answer
111 views

Deleting millions of logs in batches

I have a fast growing table with logs that I frequently have to delete (the server doesn't have much resources). It grows by at least two million entries every day. The database is a SQL Server 2012. ...
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
1answer
47 views

SQL String to get data from DB2

I decided to split the SQL Part away from This Question. Before we get started I need to let you know a critical piece of information: Due to permissions within an offsite database I am NOT allowed to ...
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 ...
1
vote
0answers
112 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 ...
-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 ...
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: ...
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
3answers
126 views

Insert row into database using values from a html form submission

I have a comments page on my site and I was wondering if it is vulnerable to some sort of sql attack or something else. At the moment users can type what they want, they can even write a php script ...
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 ...
1
vote
1answer
62 views

Reduce database touches for one to many data pull

I have the following function which works properly and returns all of the rows from a specific table, then loops through each row to add data related to it as a subarray. ...
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/...
2
votes
2answers
78 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 ...
5
votes
1answer
176 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 ...
1
vote
2answers
1k views

Using decorator and strategy pattern for dynamically generating SQL queries

This is a link to my application that actually runs on the design specified in the image. The idea behind the image is that the SubjectInfoViewer behaves as the ...
2
votes
3answers
236 views

Calculate the midpoint of a polyline

I have polylines in a GIS database. The polylines are stored using a user-defined type called ST_GEOMETRY. ST_GEOMETRY has lots of spatial functions. However, it does not have a polyline midpoint ...
2
votes
2answers
79 views

Dynamically displaying or hiding checkboxes based on region selection country. Also select All / None included

This is basically my first real venture into JS coding ... I think what I have put together here is quite long-winded and could be streamlined but I'm not quite sure how. I have a table with Columns &...
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 | ...
4
votes
1answer
88 views

Postgres Shopping Database using Python

So I have just started to work with SQL and I have tested my script and is working very well when it comes to my database. The database is used for shopping. What I mean by that is that I scrape a ...
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 ...
6
votes
1answer
2k views

Schema for Google Docs-like sharing

I want to allow users to share documents (and other stuff) in a database-driven application. I have designed the following schema to allow for this (PostgreSQL). Some of the tables like ...
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. ...
6
votes
1answer
1k views

Multi-query PHP Parser for SQL files

I have an external project, which needs to run an SQL file containing multiple SQL queries (a bit like mysqldump, if you like, but is user-created, with any kind of SQL statement/definition). PHP ...
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. ...
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 ...
1
vote
1answer
61 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. <...
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 ...
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
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 ...

1
2 3 4 5
29