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

0
votes
0answers
15 views
-2
votes
0answers
28 views

Preventing Infinite Loops PHP [on hold]

Let's say I'm building a simple ORM. The models this ORM works on can (and do) relate to each other in various ways. Most of these relations are pretty simple; however, it gets kind of tricky when ...
0
votes
0answers
24 views

MySQL stored procedure to search medical insurance claims

This stored procedure is taking a lot of time to execute. How can I optimize this query? ...
0
votes
0answers
19 views

SQL query to include one column value for one condition and exclude other columns

I am learning writing T-SQL queries can any help me writing the query for below scenario I have columns im.mfg with values(R, K, I ,Z) and ...
2
votes
2answers
57 views

SQL Query over ODBC is slow with DISTINCT

Is there any way to simplify this query? It's being run against a Progress Database via an ODBC connection. The CustomerSalesperson table has a ...
4
votes
2answers
31 views

Adding dynamic column names to a table

I'm using Microsoft SQL Server 2014 Express. I found myself wanting to add the Columns CompanyNameChangeDate (1 through 10) and ...
6
votes
2answers
42 views

Database design for a transportation company

I am designing a database and I am just wondering if I am doing it correctly. I have tables for things like State with all the states in them and then I reference the ID in other tables. But should I ...
2
votes
1answer
39 views

Sales report for an invoicing system

I am creating a sort of Sales Report for an Invoicing System. I have an extremely complex MySQL Query that takes a very long time to execute (usually about 10 - 15 seconds). It involves multiple ...
1
vote
0answers
18 views

Get percentage on the fly with AND and LIKE

Aim: Get percentage based on if field is blank or not Issue: Unknown amount of variables based on search and thus speed Solution: Dynamic SQL build up Looking for: Tips to speed up even more/spot ...
4
votes
2answers
40 views

Data import “upsert” from a SSIS package

I have the following "upsert" trigger in SQL Server 2005, which is handling a large data import from a SSIS package. It is taking a very long time to complete - I suspect due to the concatenation and ...
1
vote
2answers
49 views

Reading CSV files and inserting in a SQL database in VB.Net

This program reads all files in a folder and subfolders line by line, converts them in a supported character set, replaces all unsupported characters and inserts them in a SQL database. My idea was to ...
1
vote
1answer
31 views

Reducing the time of Update and Sum Query C# Access DB?

I have a simple query using query builder of VS2012 C# which updates the database in my winforms application. The database has 216 entries so far and it's taking a lifetime to update the database. How ...
5
votes
2answers
1k views

Wrapper for commonly used database classes

The main idea behind this class is to create a wrapper for commonly used Database classes. I'm new to SOLID principles and I'm trying to implement them in this library. Does this code adhere to SOLID ...
3
votes
0answers
12 views

Data Explorer query that makes bar graphs

I wrote a query for SEDE that I think is pretty cool. It uses the currently available graphing capabilities (scatter plots) to create a bar graph. I have used it as the subject for a self-answer on ...
1
vote
1answer
41 views

Demographics information for EDI report

I am going through some of my companies EDI reports to see if I can make them faster. The query below runs in less than one second in our AWS RDS environment, but it takes ~55 seconds on a blade in ...
1
vote
0answers
26 views

SQL query with nested subqueries

The following query is taking over 800ms to run, and returning 300 rows. ...
0
votes
1answer
25 views

SQL query with GROUP BY to show badges and points by user and course

I have the following database schema. My goal is to obtain a result set that lists the total badge points earned by each user. The badges might be earned in different courses. I want to include the ...
4
votes
1answer
53 views

SQL query that flattens many-to-one relationships

I have a database with these tables, where each mapping table represents a "many-to-one" relationship between the table on the right and the table on the left (click to enlarge): I am selecting a ...
1
vote
2answers
57 views

Select random row using PDO

What do you think of this way to generate a random number from the total rows in a table? I would like to create a page that random.php precisely generates a random ID and shows it. ...
1
vote
1answer
45 views

Get time slots based on multiple workshops

I have a list of Workshops, each having open days (Monday, Tuesday etc.) and open time and close time (which will be same for each day). Now, Based on the current time, I need to find out next 7 days ...
2
votes
1answer
27 views

Query column names and then using them in statements

I currently have a table with over 250 columns, in which ~10-15 columns have column names that have a specific prefix, namely EQP_. Assume that you do not want to ...
0
votes
1answer
30 views

Get properties from all children in a recursive SQL structure

In our product, Company is a model that can have many Companies belonging to it; so some Companies are parents, some are children, and many are both. We have a ...
5
votes
2answers
86 views

Adding an item to database + JSON

Is this code good? Or is it the noobiest PHP you've ever seen? ...
3
votes
2answers
257 views

Selecting all movies where specified actors worked together

Here's a query I wrote trying to find all movies that three actors have been in together: ...
2
votes
0answers
29 views

Altermate to CURSOR - SQL

I am currently using an iterator because I have to insert record in one table, get its primary key and add it to another table. But since it's a loop, it's very slow when data is very big. ...
3
votes
2answers
32 views

Fetch records that do not get matched in another table

I'm trying to fetch records from table PaymentToken if its AccountNumber matched but ...
2
votes
0answers
35 views

Retrieving the most recent posts from the users someone is following

I have two different implementations for retrieving posts from the users someone is following and I want to know which one you would recommend using. First I'll show you the tables, and then the two ...
1
vote
0answers
12 views

Table Trigger to update date columns

I've created the following trigger to force two columns (date_edited and date_deleted) to have the ...
3
votes
0answers
48 views

Checkout process

I'm building a checkout process where I am quite frequently making SQL connections based on user input so this is quite important. I want to know if it's well-protected from any SQL injection or other ...
1
vote
0answers
24 views

Exclusive row lock

I'm in a situation where I need to manage a kind of FIFO process within a SQL procedure. The procedure is called by a multithreaded windows application. I've created a table which look like this: ...
3
votes
0answers
32 views

Selecting the most recent record for each product

I have the following structure of a table: ...
1
vote
3answers
49 views

User-tracking history query

I have a query consisting of UNIONs. ...
1
vote
0answers
35 views

Current .NET session username injection in SQL Server stored procedures

I have a legacy WCF service that is ported from a security model using database logins and roles to a custom security. One effect of this change is that stored procedure are no longer executed using ...
8
votes
1answer
99 views

Top 10 editors partitioned by year

I wanted to get some stats on who has done the most edits on Code Review, so I wrote the following query on SE Data Explorer. All improvement suggestions are welcome. Note that I used a cursor to ...
0
votes
1answer
55 views

Finding all delivery orders with multiple purchase orders

I have a SQL query to find all delivery orders with multiple purchase orders (one-to-many). Is there a better or shorter way to write this? ...
2
votes
0answers
19 views

Generating days in a specific range

I have a query in MSSQL, where I get a summary by days from a range in a table, and this is in union with other queries. This query is used to generate days in a specific range, then add the registry ...
1
vote
2answers
35 views

Displaying a greeting to one user selected from a database

I execute the following SQL statement to get back an data object into a variable. ...
2
votes
1answer
37 views

Method to act on parameter or from iterable if not parameters are passed

The scenario is as follows. The API of my program will allow the user to perform some method on a particular element (let's say a tuple from a database). If this parameter is not passed to the ...
4
votes
2answers
116 views

DAO to create, update, and delete a project

I'm trying to write my first "complex" program in Java. So far, I created a local H2 database but I'm not sure about the quality of my code (I'm newbie in Java) because I don't know how I can deal ...
2
votes
2answers
210 views

Update user country based on IPv4 decimal address

I have UserSignatures, a table with clientIPs, some of which have CountryIds that are null ...
0
votes
1answer
28 views

Get parent folder ids by folder id(s)

My Scenario: #TmpDistinctFolderIds table contains one or many FolderId. ...
2
votes
2answers
67 views

TSQL query to gather amounts for an employees, spouses, and children in one row

I have a query that works as intended, kind of pulling from multiple records in a table, and flattening the data into one row. I am wondering if there is a faster/more semantically correct way to do ...
4
votes
2answers
102 views

Check existence of a row then update a column

not too experienced with SQL, wondering if I can make this better... I am trying to check if a row exists and then add one to the frequency column if it does, if it does not exist it should return ...
1
vote
1answer
60 views

Disposing of an SQL dataset

I am getting a compiler warning when running my code analysis. It is CA2202. It is saying that I have not properly disposed my dataset through all exception paths. Here is the code: ...
1
vote
1answer
41 views

Fetch data from multiple tables

I have three primary tables: Customer Product Order Relations: Many to many between product and order. ...
3
votes
2answers
80 views

Displaying recent buyers' feedback on games

I have the following code made to output the following: Code: ...
3
votes
1answer
58 views

Simple shop database site

I'm learning PHP, HTML and SQL - and wondered if anyone could take a look at this code and give me some feedback? ...
3
votes
0answers
39 views

SqlDataConnection update method

I'm using Microsoft's SqlDataConnection type provider. However, the only way I've seen to update a row in the database is to use something similar to this where it updates mutable values: ...
3
votes
1answer
16 views

SQL report of subscribers and their associated revenue

A user can have many subscriptions, and a subscription belongs to one plan. The plans table tells us a subscription's cost. Is the query below the correct one for ...
6
votes
2answers
172 views

Saving and Loading data with SQLite

I'm in the process of learning SQLite in C# and I've come up with some generic methods for finding and updating data. I would appreciate any pointers with the design of my methods and/or my SQL ...