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
1answer
33 views
5
votes
4answers
624 views

SharePoint CRUD class

I am writing an application where I have some objects like customer, supplier, product, etc. I have written a class for the object 'supplier' and wanted to ask if this is a good design. I have put in ...
2
votes
1answer
37 views

Checking whether a store is open or not by querying over its business hours

I currently have a method that checks if the store is open. It's working nicely, however on the main page I have quite a few stores. Whom again have different locations. Each of these locations again ...
-3
votes
0answers
28 views

Query to work out amounts

How can this query be improved? ...
4
votes
0answers
46 views

Stored procedure to insert a new person

I have not written very many stored procedures before, and this is the first one I have written to be used in a real business application to write new data into the database, so I would like to get ...
4
votes
2answers
85 views

Social network queries for profiles, posts, and followers

The code below is for a social networking system. The problem is that when there are many posts and many followers, the performance is slow. Is something wrong with the queries and the script below? ...
7
votes
0answers
29 views

Flexible Chutes & Ladders using SQL stored procedure

I thought this would be a fun exercise to use SQL to participate in the June 2016 Community Challenge, so I did. Yes, you may call me crazy! I had to write a few little things to help me, I needed a ...
1
vote
0answers
26 views

Returning direct status changes of user statuses

I have a query which returns direct status changes (no intermediary changes) of user statuses: ...
3
votes
2answers
41 views

Finding maxDate for each entity

I have a table with (CompanyNumber, File_Date, [various financial results]) I wanted to get only the most recent set of accounts for each company. After various ...
1
vote
0answers
10 views

Optimize query from xml column

So I have a query like this: ...
1
vote
2answers
75 views

Properly structuring SQLite classes/operations in Android

I am new to Android development and I want to ensure I'm learning decent practices for doing things. Right now this is my database class, which currently allows me to make a new instance of the ...
4
votes
1answer
78 views

Sanitizing words extracted from text files and writing them to a database

This code reads text files from some path, tokenizes, removes stop words, lowercases, removes punctuation and numbers, then writes the result to a database. ...
-1
votes
1answer
53 views

Getting unique Ids by bulk via sql sequence object [closed]

Following code provides unique Ids for adding new rows in a SQL database from a SQL sequence object (e.g. ...
1
vote
5answers
62 views

A like/unlike system using MySQL and PDO

I have created a Like/Unlike system. The user clicks one to indicate a "like", and clicks again to "unlike" it. Currently I do that like this: ...
0
votes
0answers
8 views

How to create a like/unlike system? [duplicate]

I'm trying to create a Like/Unlike system. Currently I do that like this: ...
1
vote
0answers
22 views

Business Access Layer and Data Access Layer for a database application

Would like to get your opinion and any advice regarding my current approach of creating database applications. Below find my current approach. Counting on your opinion and comments including examples ...
4
votes
2answers
64 views

Fetching the website version number from the database

I was just writing some code the other day, and I found myself writing something I am not sure whether it is OK to do it like this, or not. Let me give an example of what this is: I have this Method:...
2
votes
0answers
18 views

GUI rogram connecting to SQL and listing information about products in specific category

This is my very first application written in Java and so I finalized it, solely because it occurred to be my thesis. It is a very simple program that lists categories (Northwind database is used as ...
1
vote
1answer
22 views

Get all members from country depending on multiple tables

I have 4 tables, filled with some example data user table ...
0
votes
0answers
28 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? ...
2
votes
2answers
63 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
43 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
51 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
44 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
20 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
3answers
52 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
57 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
43 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 ...
7
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
14 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
43 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
37 views

SQL query with nested subqueries

The following query is taking over 800ms to run, and returning 300 rows. ...
0
votes
1answer
31 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
57 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
80 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
47 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
31 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
31 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
99 views

Adding an item to database + JSON

Is this code good? Or is it the noobiest PHP you've ever seen? ...
3
votes
2answers
289 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
31 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. ...
0
votes
0answers
13 views

Select Server Settings from one table if the status reads 'issued' in another (mySQL stored procedure)

I'm just wondering if this is OK to do. If I don't have the else statement I get an SQLException because the query doesn't return a result. Is there a better way? <...
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
38 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
13 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 ...