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
3
votes
1answer
26 views

Parse table names and attributes from SQL queries in a dataframe

I want to get table names and column names from queries in a dataframe. The dataframe is like this: ...
-2
votes
0answers
21 views

Query is running slow even when the tables are indexed [on hold]

The below query takes roughly 2 minutes for almost 2000+ records. The tables are indexed. what might be causing the issue? ...
-1
votes
0answers
11 views

JOIN and NOT EXISTS query in mongoose [closed]

I have a sql query which I need to convert in mongoose aggregate SQL: ...
4
votes
2answers
109 views
0
votes
1answer
27 views

Updating field in Temporary table

I have a more massive sp, in which I use some temporary tables, below is a part of the sp where I am updating a field in a temporary table two times. ...
0
votes
1answer
85 views

Retrieve objects stored in multiple tables [closed]

Suppose I have a complex object Person that depends on several other objects: ...
3
votes
1answer
41 views

Calculating all flight connections

I am working on an API to return all the possible flight route between point A and B. I have a set of data which includes the flight number, airline, departure airport, destination airport, ...
0
votes
1answer
15 views

Querying nearest city with a given shop using latitude and longitude is slow

I am using the following query to search for the nearest city to my location from the cities table using latitude and longitude. The query also checks whether the nearest cities to my location have ...
3
votes
1answer
94 views

Small application for manipulating users and their activities

I made a small application using C#, SQL Database, entity framework , and windows forms to manipulate users (...
3
votes
1answer
23 views

Billing and recurrent payment db structure

I am designing my first payment service and here is my db structure. Each user can have many businesses, each business can have many products. Some are recurring, some are paid once. Each product is ...
2
votes
2answers
55 views

Shopping cart with Ajax

I build a cart for an ecommerce website, and I want to know if I did well. I want to record the changes in the DB and display the information from the DB to the customer. To be sure that what he sees ...
2
votes
1answer
46 views

Abstracting a SQL Server Table builder

I'm working with SQL Server 2008 and wanted to make table builder, similar to Laravel's migration classes. I would like to be able to expand this down the road but the main purpose of this code will ...
1
vote
2answers
56 views

Combining two queries in one

What I want is getting all names (first, middle, last) of the users along with each of their total hours of work which will be calculated by the SQL statement: ...
1
vote
0answers
16 views

Select splat in a subquery [closed]

Obviously, 'select *' is never a good idea. HOWEVER, I have taken a job with an org that allowed this cancer to spread. They have huge queries, using ...
1
vote
0answers
13 views

Custom WordPress SQL query to get posts and users using term_id

I have a WordPress site with multiple custom post types, that all share a common custom taxonomy. Users can also be tagged with terms from this taxonomy. After giving up on ...
2
votes
1answer
60 views

Generating and storing a unique salt in Oracle database using Java

This is my account table: ...
1
vote
1answer
54 views

Displaying a paginated list of forum topics using PHP PDO [closed]

Can someone tell me if this code is safe? Can be sql-injected or something else hacked? Code get some rows from db and show in pages with pagination... if i can improve let me know and show me how, ...
1
vote
1answer
43 views

T-SQL query Choose name of clients, concluded more than one loan agreement in 2010

QUESTION: Choose the name of clients, concluded more than one loan agreement in 2010, as the numbers and dates of issue of these contracts. Sort by name of the client and date of issue of the loan. ...
0
votes
0answers
34 views

Parties and Messages in SQL e-Commerce db design

I'm posting a follow-up question based on my first question. My goal is to, as an exercise for myself, create a complex (in my opinion) e-commerce application. The explanation of the application can ...
2
votes
0answers
19 views

T-SQL Query remove duplicates except for original row from the table

Question: There is an Exam_Merge table into which to import records from a similarly structured table in another database. In this case, the Exam_Merge table contains the values of the primary key ID ...
4
votes
1answer
178 views

SQL query to count loans issued during each week

Calculate the number of loans issued by the Regional offices for each business week in the period from 38 to 40 business week of 2011 inclusive. Sort by name of the regional unit, business week. ...
4
votes
1answer
35 views

JSON from SQL Server: Reduce lists of single dicts to list of values

SQL Server 2016 introduced some JSON features, but they're far from robust. As far as I can tell, there's no way yet to output a simple array; everything must be in ...
4
votes
1answer
77 views

SQL e-commerce database design

I want as an exercise to create an e-commerce application from bottom up. My main goal here is to gain a lot of knowledge. I have experience in web development, but never have been there from the ...
4
votes
1answer
85 views

PHP Login Class - Security and Efficiency Check

I'm hoping someone would be able to identify if my code is prone to SQL injections, and just overall see if there is anything that could be done better, faster or more efficiently Im very new to OOP ...
1
vote
1answer
47 views

Query to generate payroll based on attendance for a month

I have written a query to generate payroll based on attendance for a month, for about 4000 employees. It takes quite a long time to execute. Basically, what I am doing is to joining two different ...
4
votes
1answer
31 views

Calculating elapsed time

The code below compares recv.rcpt_dtim (which is a datetime type) against the current date/time. It calculates an elapsed time resulting in hours and minutes formatted like: "04:22". It took me a ...
1
vote
1answer
33 views

Insert multiple rows without using CURSOR SQL Server 2014

I have a fairly complex query which insert multiple rows into a table from multiple tables. Its works fine but I really don't want to use cursor as some blog says cursor took long time for execution (...
1
vote
0answers
22 views

Log table with a summary of claims

I'm writing a log table which contains the summary of the claims. The log table logs the data whenever there is an upload. I have written the following SQL query. Though it serves the purpose, I'm ...
2
votes
1answer
39 views

SafeBlockPopulator to ensure neighboring chunks are generated before population

Bukkit/CraftBukkit/Spigot are Minecraft server extenders that allow for creating and using plugins. A particular type of plugin is a generator, which creates the game world. Generators operate chunk-...
5
votes
1answer
74 views

Lastest version of my Blackjack game

This is the latest version of my Blackjack game that uses a MySQL database to store user info. I did everything I was recommended in my previous post, added a ranking system and also fixed a bug where ...
1
vote
1answer
52 views

Search by parameters from multiple tables

I wrote a query that searches people based on search parameters from 3 other tables (phones, ...
0
votes
1answer
41 views

Saving row versions in MySQL [closed]

I just want to confirm that I am versioning my "versionable" fields correctly, and that there isn't another, better way to do this. I have a table event, a record ...
0
votes
0answers
24 views

Ensuring referential integrity in child, group relationship

I'm not going to lie - Sql Server is not in the top 10 of my skill set, but it's something that I have to do from time to time. What's more, I'm using Entity Framework, so there is a workaround ...
1
vote
0answers
47 views

Running an UPDATE SQL QUERY within VBA using DAO

I have a macro in Excel that updates a recordset using WHERE a primary key in MS Access matches a primary key in a UserForm label value. The macro is called from a ...
3
votes
2answers
204 views

Database Model Security For Book Inventory

This code is one of the models developed for the Book Inventory application that is open for review. It is also based on a comment on this answer to a C# question. Based on the comment I did some ...
3
votes
0answers
24 views

spark takes long time for checking an array of items present in another array

I am new to spark. I have two dataframes df1 and df2. df1 has three rows. df2 has more than few million rows. I want to check whether all items in df2 are in transaction of df1, if so sum up the costs....
2
votes
1answer
79 views

Web Server handler class to pass IIS http requests to SQL Server stored procedures

This is a c# class I use to implement web database applications with Microsoft IIS and Microsoft SQL server. It passes the http context to a selected SQL stored procedure, and writes a response based ...
1
vote
0answers
21 views

Fetching SQL table names and dynamicly insert values

I need to make a UI where I can edit/insert/remove records of my SQL tables through my app. Edits and deletes of records works fine except of insertions when it comes to tables with auto-incremented ...
1
vote
1answer
37 views

Listing people with their phone numbers (if any)

I have the following tables in my database: ...
1
vote
1answer
185 views

Simple join between 2 tables with unusual structure

I have two tables as below ACCOUNTS: ...
1
vote
1answer
42 views

Read comma separated values and insert in SQL Server 2016 table using String_Split

I know that this question has been asked many times over many years and I have read every one of them but I wanted to get a modern solution since software has changed and ...
3
votes
2answers
100 views

SQL Query - records within the last year

Bit of a complicated one for me. I have a database full of hundreds of thousands of records, many of which are duplicated. I need to get all records within the last year but making sure every ...
0
votes
0answers
15 views

Optimize slow SQL stored procedure that calculate Test Case failures in a non-optimal schema

I need to heavily optimize the following sql stored procedure (MySQL 5.6). Requirements: Should be as fast as possible (this is a key) Lots of records (10 M now, possibly more) Stored procedure ...
2
votes
1answer
62 views

Blackjack game with database - follow-up

This is a follow-up to my ex-posted Blackjack game that uses a MySQL database to store the accounts and user's money. I tried splitting display_info() a bit, I also ...
3
votes
1answer
84 views

Blackjack game with database

This is the latest version of my Blackjack game and I did a quite big update to it. Now you can make an account that is saved in the MySQL database and you can bet money that are also saved in the ...
4
votes
1answer
74 views

Registration and login script

This is a registration and login script I have made in Python 3. It uses a MySQL database. In the future I might use it with my Blackjack game and add a row called ...
1
vote
0answers
30 views

Determining daylight-saving time in Central European Time

The following constellation: Our applications passes date&time around (in the most horrible way possible). We want to simplify this. Instead of a culture-specific string like '31.12.2019', we're ...
1
vote
0answers
43 views

Writing SQL queries to retrieve data from given tables

Good day, I am a college student and lately we had an assignment where we were tasked to write SQL commands on various questions depending on the information that is needed to be displayed from 3 ...
3
votes
2answers
77 views

Download and save bulk URL concurrently

I am new to Go and wrote program to download and save bulk URLs concurrently. It is working correctly, but I would like to make it more efficient and follow best practices. ...
2
votes
0answers
43 views

Generic library for querying various kinds of databases

Since C# 8 and .Net Core 3 are going to be released sometime this year, I wanted to try and convert the library I made to make querying databases easier, implementing the already accepted features (...