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.

learn more… | top users | synonyms

1
vote
0answers
3 views

How do I optimize this MySQL query?

I have the following query. I know there's an easier way to do this without the subqueries, or at least optimizing how they're used. I've read about cross joins and using HAVING but cannot figure out ...
0
votes
0answers
6 views

SQL Stored Procedure Get Distinct and Update

The idea: To show how many times a user (by EmployeeID) is in the TblTableList and then update the TblTableStatusCount I have been learning Fetch this week so wanted to ensure I have gone down the ...
8
votes
2answers
60 views

FizzBuzz in SQLite 2

This query performs a FizzBuzz in SQLite 2.8.17 without creating any tables or sprocs. First attempt: ...
4
votes
1answer
65 views

Put it in a bucket

You're running a jeans company. Your system is collecting detailed orders' data, but it's a bit archaic and it's storing the number of units ordered per size in a delimited string with 20 "fields", ...
9
votes
2answers
200 views

FizzBuzz in SQL--no loops

MS SQL Server, no loops. ;) ...
5
votes
1answer
30 views

Using SQL to reorder items in a list view - is this efficient?

I'm writing an application for work that requires me to process a list of transactions. The list is small (5 records at the most) and I'm required to display that data in an android ...
0
votes
0answers
12 views

Are these linked server queries susceptible to SQL injection? [migrated]

I'm using a stored procedure to generate a create table script on the fly based on parameters passed into it. I am validating that the server exists, and then validating if the table exists in the ...
5
votes
0answers
36 views

Loading datawarehouse with dynamic sql

For a datawarehousing project I ran into the following: custom fields that users can create, modify and delete, that should be loaded into the datawarehouse as they are when the ETL happens. On the ...
2
votes
2answers
33 views

Using Common Table Expression and Outer queries

In following query I'm use both Common Table Expression and Outer queries. Apparently both looks same to me. If I summarize my requirement, I have employees in ...
5
votes
2answers
52 views

Inserting tables with foreign key

How can I improve this method that adds data to three tables in the database? The tables are: UserTable UserInfoTable ...
10
votes
2answers
61 views

Revision 1 - 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 ...
5
votes
5answers
421 views

Username, Password and UserType Validation

I have two tables in the database: Credentials (userid, password, usertype) Customer ...
12
votes
2answers
105 views

Nokogiri crawler

The following code works but is a mess. But being totally new to Ruby I have had big problems trying to refactor it into something resembling clean OOP code. Could you help with this and explain what ...
6
votes
1answer
62 views

Is there a way to optimize this aggregate postgreSQL statement by using CASE?

I have a working SQL statement which shows the following: Player Champion Role Total Kill/Death Ratio Total Kill+Assist/Death Ratio Total Win % Difference between Ratio from one month ago Difference ...
4
votes
4answers
485 views

Two while for the same query

If I have to loop results of a query echoing first all fields of a column, then echoing something not to loop, then fields of another column. ...
2
votes
1answer
14 views

Query the Max Nth per group

I'm trying to write the most efficient query I can to pull the relevant data I need for retrieving the latest conversations for a user, ordering groupings of conversations by most recent message in ...
4
votes
3answers
52 views

Building SQL from multiple combinations of query parameters

I have a node.js/express.js based REST application. In one GET service I am querying data based on different set of request parameters. I am looking for a better way to implement it. ...
10
votes
3answers
287 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
447 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
52 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
63 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 ...
2
votes
1answer
51 views

Ruby Bot application [closed]

I just want to know if this looks good. ...
0
votes
1answer
75 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 ...
9
votes
1answer
65 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
61 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
222 views

Multiple SQL queries, one per ID

ids contains 100 ids that are comma delimited. Is it fine or does it need improvement? ...
2
votes
0answers
27 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 ...
10
votes
2answers
195 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 ...
4
votes
2answers
95 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
153 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
57 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
155 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
134 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 ...
4
votes
2answers
106 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
96 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
48 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
85 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
112 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
77 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
109 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
43 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
42 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
57 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
461 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 ...