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.
10
votes
3answers
243 views
Is there any way to speed up this stored procedure?
Is there any way to optimize this stored procedure? Maybe something instead of so many joins?
It takes some time to execute. Maybe there are other options that I could look into?
...
7
votes
4answers
420 views
Find if value exists using SQL True/False Return
Aim: To Assess if one, or more, examples of a value exists in a Database in the quickest time as I only needs a True/False result.
The variable is Alphanumeric.
Question: Is this the quickest and ...
7
votes
1answer
43 views
Step 1: PsychoProductions management tool project
I started a project to build my own invoicing and management system to take the place of prohibitively expensive QuickBooks software. This will be broken down in 5 steps, with the current step in bold ...
2
votes
1answer
53 views
UserDAO with CRUD functionality for my UserRepository
This is my first attempt at creating a DAO.
I would like to get some feedback regarding the following aspects if possible:
Code readability
Efficiency
Usability
I also would appreciate any other ...
0
votes
0answers
45 views
Optimizing Laravel Eloquent Multiple Joins
The following is readable SQL for Eloquent that I have created that works. The down side is that it looks more like a 1:1 with SQL and I don't think I'm using the full potential of Eloquent. I thought ...
0
votes
0answers
25 views
Writing Hibernate SQL query without exceptions [closed]
Below is the hibernate query I have written:
...
2
votes
1answer
43 views
2
votes
0answers
33 views
EF6-Lambda Expressions deep big-tree query
I am looking to improve the following query.
We are using EF6 (CodeFirst) and C# Lambda Expressions, and Repository/Unit of Work patterns. Also, we needed to restrict the query in a way that we ...
0
votes
1answer
71 views
Did you like my product?
I have the following MySQL query which selects product details and whether the viewing user likes them. I feel like it could be more efficient and that there is a more practical approach than using a ...
8
votes
1answer
54 views
Tic-tac-toe in SQL with optimal AI
The simplest introduction to this code is to play it! Here's an SQL Fiddle. However, to enjoy it fully, you'll need a more interactive environment, like the psql ...
8
votes
1answer
58 views
SQL Tic-Tac-Toe attempt
In an attempt to practice conditional statements in SQL I decided to design a tic-tac-toe game with MySQL. Let me know if you think any of the steps could be done better.
Step 1: Create the game ...
6
votes
4answers
180 views
Multiple SQL queries, one per ID
ids contains 100 ids that are comma delimited. Is it fine or does it need improvement?
...
1
vote
0answers
14 views
EF query for calculating monthly trends
My application has a fairly important query that is used in a lot of places. Unfortunately it takes about 14 seconds to run, so I'd like to find a way of possibly improving it.
The application ...
9
votes
2answers
179 views
Find records with duplicate serial number
I was tasked today with cleaning up data from a SSRS report put together by a DB programmer. The original report was to find duplicate serial number sales within a user-defined period of time. I was ...
3
votes
2answers
84 views
User Search SQL Builder
Using the VS2012 code analyzer i see the following code has a pretty low Maintainability Index(40) but i cant seem to think of a better way to design it. Does anyone have suggestions on cleaning this ...
0
votes
0answers
6 views
“Wide” vs “Long” Database Structure - Is there a logic when to use which? [migrated]
I'm currently setting up a database to house records for an application I'm writing and am trying to come up with the most efficient DB structure to use... Of course I know that there are as many ...
4
votes
2answers
149 views
Injections and query
I made a class that connects to my DB and inserts some values. Is it secure or how can I protect this further from injections? The object declaration will come from variables with POST from a form, ...
5
votes
1answer
54 views
How can I optimize this SQL ranking generator query?
I have a World Cup fixture app where people can guess the results of the matches. Everything is working great, but each time I update the ranking, it takes 20 minutes for just 3000 users. So there ...
10
votes
2answers
149 views
Complex query to count votes with a redistribution system
I've spent the last couple of evenings trying to build a system for redistribution of votes in a ranked voting system. I've finally come up with the model for redistributing surpluses from a candidate ...
3
votes
1answer
91 views
MS Access VBA code to compare records in a table and combine data - revised
I've previously posted a version of this code here:
MS Access VBA code to compare records in a table and combine data where necessary
To repeat what I'm looking for from my previous post:
Note I ...
2
votes
1answer
37 views
4
votes
2answers
72 views
MS Access VBA code to compare records in a table and combine data where necessary
I need to process some data which is the output from a CAD system, namely a Bill of Materials.
I've constructed database and written some VBA code to achieve this. An explanation of what this code ...
1
vote
1answer
54 views
Slow delete query on table with composite index
after profiling my application, it turns out that a single method is taking 3 minutes to run, which is about a third of the total runtime.
The method deletes approx. 400.000 rows from each table ...
5
votes
2answers
90 views
Adding object to database, using linq or sql connection
I have a table called tblDelegates in my database which I need to populate with some data. I have created a class called Delegates which has various properties to ...
4
votes
1answer
45 views
Idiomatic way to construct a SQL INSERT query in Python
I have a bit of code to insert some values in a table. It seems a bit clunky - is there a neater way?
words is a list of dictionaries, and the entries contain other fields which I don't want to ...
3
votes
2answers
84 views
Asking a user to take money from a checking account and move it to a savings account (Revised)
I made a few changes to the source code based on several suggestions I received yesterday. The changes I made were: improved the names of methods and variables to better describe what they do, passed ...
7
votes
1answer
97 views
Fluent Nhibernate, is the mapping correct?
I'm very new to NHibernate and DB. I have three tables which are connected with many to many relationship.
Here are the tables creation Script:
...
11
votes
7answers
1k views
Asking a user to take money from a checking account and move it to a savings account
I'm aiming to get this program right as I might show it at a job interview. The code below runs fine but I would like to know if there's anything that can be improved in terms of readability, good ...
5
votes
2answers
74 views
Modifying `sakila` database
This is not "real life" code. I'm trying to expand upon the well known Sakila sample database for MySQL to make it more complex. Step 7 (or 6) is running ...
1
vote
2answers
101 views
C# to Access SQL query based on UI controls
I have a WPF application (using MVVM pattern) that allows users to perform a search for a record/records based on their ...
1
vote
1answer
42 views
Am I using SQL group correctly?
I need to get a count of correct and incorrect attempts per testID, so my query is:
...
4
votes
0answers
39 views
Neatly Transforming Anorm ResultSet Into Map[Parent , (Set[Child1], Set[Child2]))]
I have a table Bill containing Bills with 0...n relationships to Material and ...
-2
votes
1answer
56 views
ColdFusion Oracle Sql Injection Example [closed]
Assuming ColdFusion 10,0,13,287689 and Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production.
With this example...
...
5
votes
4answers
96 views
SEDE-Query for Rep-Trivia
The code should be relatively self-explanatory. I was wondering how much rep the Top Voters on sites did "generate" on a site, in comparison to how much rep they "own".
Therefore I created a little ...
5
votes
1answer
459 views
Can I populate this table faster?
I have the following SQL query which takes ~3 seconds to run, maybe ~4. This populates a consultants table with their expected payments for the month.
Unfortunately, the page only loads when this ...
7
votes
2answers
1k views
Is my Java SQL connection secure from hackers?
I would like to know if my java db class is enough protected against hackers. (I'm currently developing an Android application). I protect it with a infos.properties file which contains every ...
2
votes
2answers
68 views
Nested SQL Statement
I haven't done too many nested statements in MySQL and I was hoping to have the below SQL looked at and let me know if there is a better/more efficient way of doing what I am trying to accomplish.
...
4
votes
2answers
49 views
Long SQL query with much duplication between two halves of a UNION
This works, but it's huge.
We need to repeat each table column on each UNION SELECT, as well as the WHERE clause for ...
2
votes
1answer
53 views
Delivery geolocations query
I have the below MySQL query that does exactly what I need. But I am sure there are better queries that do the same thing.
If you see something very ugly or bad and have any suggestions, I will be ...
1
vote
2answers
57 views
Text file searching using SQL
I have the need to search a directory containing 1000+ files on remote servers where I only have access to SQL Server Management Studio and Explorer. I have written the below SQL statement which does ...
5
votes
1answer
72 views
Selecting one MySQL date with month reduced by one
I was thinking in a way to improve the following query if possible:
...
6
votes
1answer
98 views
1
vote
1answer
37 views
Execute edit in a stored procedure based on database value
I have code below which is set to check the date of DateToComplete, and if the date is 2 weeks or more ago, change the status of Complete from 3 to 2.
Is this the ...
-1
votes
1answer
91 views
Is this shopping site safe from SQL injection attacks? [closed]
Please verify security from SQL injection attacks.
homepage.php
...
2
votes
2answers
55 views
Abusive use of long database query?
I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries.
For example, I had a function that does this:
...
10
votes
4answers
695 views
Is this function vulnerable to SQL injection?
I've this function to list products from database by category. I'm using prepared statements but wouldn't this make it pretty pointless to use them?
...
1
vote
3answers
122 views
Making a new column and setting default values equal to the COUNT of a certain condition in SQL? [closed]
I have 2 tables. (table1, table2)
Now, I would like to do something along the lines of:
...
5
votes
1answer
69 views
Tuning a query for performance
I am running this query and it takes several minutes to complete. How can I tune it (unfortunately I don't have the privileges to run an SQL tuning advisor)?
...
5
votes
1answer
145 views
Length limited listagg for muliple m:n relations in a view
I have a few views that all follow the same pattern. They select a primary key from some main table and then a few semicolon seperated strings of captions of related rows over many-to-many relations. ...
7
votes
1answer
73 views
A faster way to combine two SQL table
I would like to give it a try and ask about my codes on here from now on to see if there are improvement for'em
this code is supposed to combine two sql tables into one.
...