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

13
votes
5answers
419 views

Average time to first answer

Just trying out my T-SQL foo. Wrote a script to get the average time (in seconds) to first answer for a specified language. ...
5
votes
3answers
210 views

Extracting certain records

The purpose of this SQL query would be to extract the record 10192 only, because the end_time is both in the past and its foreign counterpart in the Node table ...
2
votes
1answer
27 views

Reusing select statement

I am checking if there are any rows in a table with some conditions. If there are more than 1 row, it should filter again with some more conditions. ...
6
votes
1answer
37 views

Trying to avoid a double full scan with aggregates in query

I have a statistics query I'm trying to run against the below table: ...
5
votes
0answers
44 views

Selecting template from database using organization ids

This is my first SQL post over here, and in fact, I have more or less the experience of a regular SQL programmer, except that the task at hand this time was way harder than normal. I am expecting, ...
4
votes
3answers
195 views

SQL percentage calculation

I have created a query in which there is a column that calculates a percentage: ...
4
votes
1answer
68 views

Batch of SQL statements in a single query

I'm using the following query for multiple transactions. This is the scenario. Generate Salary (this is not in the scope of the query) I have employee attendance in ...
6
votes
2answers
257 views

Multiple SQL statements in a single transaction

Using the following query I'm doing transactions with two tables ...
7
votes
2answers
40 views

Revision 2 - Step 1: PsychoProductions management tool project

I have been told by DBA.SE people that this was off-topic for DBA.SE and should be on CR.SE instead. So... here I submit this database schema design for my trusted fellow CRitters to review! This is ...
4
votes
3answers
67 views

Web application to insert into MySQL database

I'm currently learning PHP, SQL/MySQL and HTML to develop a web application project (I have very little practical experience in all of these.) To get started, I spent far too long and many questions ...
4
votes
1answer
35 views

Unifying XML formatting with inheritable parsing

Inspired by the XML format for game data question, I was interested to see how my system works for storing game data. My system works a lot like Halo, where there are a variety of gametypes and ...
20
votes
2answers
2k views

Tired of FizzBuzz yet?

There have been many FizzBuzz questions lately, and here is one more! Granted, it is pretty straightforward to do FizzBuzz with SQL using calculations. So instead, I'm going to do a FizzBuzz which ...
8
votes
1answer
65 views

Abusing Excel VBA… to maintain data stored in a database

I need to build a little UI to allow easy maintenance of some data stored in a MySQL database, and the end user wants to do that in Excel (I know, I know). The code I came up with comes pretty close ...
11
votes
2answers
514 views

PHP URL Shortener

I just developed a URL shortener. index.php: ...
5
votes
1answer
42 views

Library database search with multiple JOINs is too slow

I have a MySQL query which runs very slowly. I've rewritten it many times but no improvements yet. My current query for advanced search takes about 60 secs to complete. Any suggestions for improving ...
6
votes
0answers
63 views

Executing large SQL script file with GO statements using ADO

I wrote a small component (still in the works but working) which takes a large SQL script file, splits it into different "blocks" based on GO statements, and executes them one by one. The only major ...
4
votes
1answer
36 views

Speeding up class that uses an ODBC connection

I have created a class that gets data from an ODBC connection. The code works but it is really slow - I'm talking up to 1.20ish minutes to run. I know my code is inefficient but I'm really not sure ...
7
votes
3answers
151 views

Getting the top 10 stores within a category

I have the following query. I know there's an easier way to do this without the sub queries, or at least optimizing how they're used. I've read about cross joins and using ...
6
votes
3answers
63 views

SQL Stored Procedure Get Distinct and Update

The idea is to show how many times a user (by EmployeeID) is in the TblTableList and then update the ...
8
votes
2answers
64 views

FizzBuzz in SQLite 2

This query performs a FizzBuzz in SQLite 2.8.17 without creating any tables or sprocs. First attempt: ...
6
votes
2answers
92 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", ...
12
votes
2answers
297 views

FizzBuzz in SQL--no loops

MS SQL Server, no loops. ;) ...
5
votes
1answer
38 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
13 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 ...
9
votes
1answer
61 views

Loading Data Warehouse with Dynamic SQL

For a data warehousing project I ran into the following: Custom fields that users can create, modify and delete, that should be loaded into the data warehouse as they are when the ETL happens. On ...
2
votes
2answers
37 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
60 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 ...
11
votes
2answers
78 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
448 views

Username, Password and UserType Validation

I have two tables in the database: Credentials (userid, password, usertype) Customer ...
13
votes
2answers
115 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
492 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
15 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
56 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
297 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? ...
8
votes
4answers
466 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
53 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
67 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
54 views

Ruby Bot application [closed]

I just want to know if this looks good. ...
4
votes
3answers
145 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
74 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 ...
9
votes
1answer
94 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
249 views

Multiple SQL queries, one per ID

ids contains 100 ids that are comma delimited. Is it fine or does it need improvement? ...
5
votes
1answer
56 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 ...
11
votes
2answers
211 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
100 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 ...
4
votes
2answers
155 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
58 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
163 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
190 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 ...