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

3
votes
3answers
98 views

Parsing multiple line records using Java 8 Streams

There was a suggestion in this StackOverflow question to move this question here. I added some more information and restructured the question a bit. I'm trying to parse the following file which ...
-4
votes
0answers
37 views

Can this Excel VBA with ADODB connection to Access database be improved in performance?

I have an issue: speed in Excel retrieving data from Access external database (47 sec. --> I want to reach 3 seconds) Excel 2010 Access 2000. Suggestions: Add Library reference for Microsoft ...
3
votes
0answers
27 views

Updating results when an opinion poll is answered

Let's say I am trying to build an opinion poll app, such that I can create a template of an opinion poll, give it multiple sections/questions, assign multiple people to different copies of a given ...
6
votes
1answer
52 views

Listing payments where all payments lines and transactions are closed

The goal of this query is to get a list of payments where all the corresponding payment lines and transactions have the status CLOSED. These are one to many relationships. The database is Informix. I ...
4
votes
1answer
34 views

SQL + VBA Populating Data in Cell Range

I currently have a code that is connecting to SQL database in VBA. The data is populating correctly. However, I was wondering if there is a way to condense the code below. I have 4 different columns ...
4
votes
0answers
30 views

SELECTing percentage and count of votes

I have the following tables structures: ...
1
vote
1answer
32 views

Performance of summing one value from join of three tables

I have a table I want to get a sum of information on, but the value I need to query on is in two different tables. The one with values I need to sum is say, kudos, which has a value indicating +1 ...
4
votes
2answers
77 views

C# Method to determine database status

I have a task that I am trying to complete and would appreciate direction, to know which is the most efficient path to take for future requirements. Use Case: A background process that determines if ...
2
votes
1answer
50 views

WordPress anti-spam script

This is the first PHP script I have written. It downloads and installs a plugin called "anti-spam" by using the WordPress API. It also provides an option to either delete all comments or delete the ...
1
vote
1answer
44 views

Stored procedure where column to ORDER BY depends on input parameters

I'm getting three inputs and based on those three inputs, I'm returning. Input items may vary, so I used CASE WHEN statements here. Is this code correct? If so, ...
3
votes
2answers
42 views

Updating user log in time while he logs in to the web page

My intention is to store the user's last login date and time when he logs in to the web page. I pass his username and password to the stored procedure to check whether is it correct or not! I believe ...
1
vote
0answers
27 views

Association count in single query for ActiveRecord

This is a small gem that gives the possibility to include counts of reflections when fetching active record objects. What do you think of the code? Any improvements or other (similar) use cases where ...
3
votes
2answers
38 views

Supervisors and employees query, with a subselect and inner join

I want to replace or improve the SELECT command of tblVisor to make it faster. Is there any way to improve this SQL command? ...
4
votes
1answer
31 views

Checking that data has been created in multiple tables

I have 4 tables that I want to check for data. When there are Rows in all the tables, I want to print a message for success. When there aren't any rows in any table I print an error (when 1 or more ...
7
votes
2answers
48 views

Query to find users from where?

Based on my question here, I have updated my query to take user input so it can be a generic query: ...
4
votes
1answer
90 views

Acquiring an ID from a newly inserted entry in an MSSQL database

In an MSSQL database, I have automatically increasing IDs for every entry. Is it safe to acquire the ID of the newly inserted entry like this? I am worried that, if at the exact same time another ...
5
votes
2answers
45 views

1st questions with answers within X hours

I recently challenged @Hosch520 with writing a query as such: Find first questions with answers posted within 24 hours And he did great. I figured I would have a go at it too. Turns out I ...
1
vote
1answer
40 views

Perform SELECT INTO Statement and add Primary Key afterwards

How can I improve this TSQL Statement in terms of performance? ...
3
votes
1answer
41 views

Find first questions with answers posted within 24 hours

So, sᴉɔuɐɹɥԀ suggested I write a SEDE query to find first questions with answers posted within 24 hours, and here it is: ...
6
votes
4answers
1k views

Query to find users from Australia

After a discussion of which users were from Australia, I wrote my first SQL query to find out: ...
4
votes
1answer
78 views

Classes for reading data from Sql Server into objects

The following is a set of classes that read metadata from Sql Server tables and populates local objects. It works, but I feel like there's too much duplication happening and too many places changes ...
3
votes
1answer
131 views

Handling new user requests from a Swift client

I am starting to play with POST request to save in my server the user token so I can send push notifications in Swift (this is the swift code). This is the PHP file that processes the request (please ...
1
vote
1answer
34 views

Bookmaker odds and offers query

The following query returns the latest Odds for each Offer based on the timestamp on the ...
2
votes
1answer
59 views

Controller to list users

I think I put too much code in my controller that was supposed to go in the model. This is a part of my controller, I'm not gonna paste everything since there is a lot of code. ...
8
votes
1answer
54 views

Assigning permissions to new role without RBAR

I'm currently faced with a problem in our SQL Server environments. We need to migrate our existing logins, users and roles to a new login, user and role with the same permissions as the old. I've been ...
2
votes
2answers
81 views

Users and friends query with retry, returning JSON

I am new to Azure and SQL. I have the following function that is part of a larger Web-API which is hosted on Azure and is querying an SQL Server database that is also hosted on the Azure platform: ...
6
votes
1answer
43 views

SearchSchoolData - what class where?

I am running a test load using Telerik Test Studio using 100 users at once entering search filters on a page that calls a stored procedure. My application that calls the stored procedure is an asp.net ...
3
votes
2answers
33 views

SQL server efficiency, comparing date time of latest record and the one under it

I have a snippet of SQL that compares the last two records and gives the datediff in seconds. However, the way I have it is quite slow, taking up to 20 seconds to execute depending on how many ...
1
vote
1answer
101 views

Populating an HTML combo box by looped concatenation

This code takes the results of a database query and uses them to populate the options in a combobox on a form. Would it be better to start with an empty htmlCode ...
3
votes
1answer
73 views

Matchmaking system - sorting musicians by skills, genres, and location

I'm making a matchmaking system using PHP and MySQL which allows users to search through a list of musicians so that they can find people with the right skills and interests who are near them. It ...
1
vote
2answers
163 views

Multi-Table Unions [closed]

I've been using joins for years but in this instance I want to be able to do different queries on different tables which may have different structures due to clients. Long term we are aiming to make ...
6
votes
4answers
261 views

Sonar remarks make SQL unreadable?

I ran the following code through Sonar, a static analysis tool. Original file: ...
5
votes
1answer
78 views

PostgreSQL multiple processes and queries or nested query

I have a series of tables and queries I run a process against and at times this process can take hours - if not multiple days - depending on the date range I select. I am running PostgreSQL 9.4. In ...
2
votes
1answer
117 views

SQL Dependency with Broker

I have written a windows service for one of our local servers. This service works like a gem on my local machine, does what it's supposed to (ACCP to exchange db data), but I'm not overly familiar ...
3
votes
2answers
50 views

Eager load additional data about some instructors

Below is a snippet of code of a little practice project. I am still pretty new to EF and I was wondering if there is a way to write the below statement so that all required data is eager loaded since ...
2
votes
2answers
49 views

Query using cross join or inner join

Please consider the following three tables that I am playing with in the image below: I want to come up with a SQL Query which shows first_name, last_name, and the total amount of all orders for ...
1
vote
1answer
169 views

Two tables for storing comments

I have two tables for storing comments comments ...
7
votes
2answers
710 views

Preventing SQL injection by converting all characters to their ASCII values

Scenario In order to prevent SQL injection, I'm converting every character of a string to be inserted in the database into its ASCII value before performing the query; in order to read the value of ...
1
vote
1answer
77 views

Performance shifting for SQL Database and Linq memory grouping

I am messing around with shifting between stored procedures and business layer EF getting data rapidly then processing in memory. This works and on a static data range of 3 months I get execution ...
4
votes
1answer
55 views

Luhn algorithm MS-SQL

This a solution Luhn algorithm for credit validation. This algorithm is a basic one inspired by wikipedia. I mean no check for length, type, and so on. You can enhance the base code as you want it to ...
1
vote
2answers
63 views

SQL Data Fetcher for CMS

I am creating a CMS for a website, so I've added most of the functions that will fetch data from the database to a separate class. The code doesn't seem to have any bugs(Since I've tested it) but I ...
1
vote
0answers
56 views

prestashop: get final product category

In general, in prestashop there are no funcions to really have the final (the one with highest level_depth) category of a product based on id_product, so I extended the Product class and added this ...
5
votes
3answers
137 views

SQL database design for ecommerce

I need to create a database which stores details products, Manufactures,Suppliers. So initially I divided Products into categories and subcategories. These are the tables I created. ...
3
votes
1answer
106 views

Optimizing a Query in Entity Framework

I'm wondering what can be done to optimize the following. I've tried to note the points at which most of the overhead is occurring. The main two points I see are The call to DiffDays from within ...
3
votes
1answer
44 views

Join - order by vote-sum and check if user has voted

I have a vote and a comment table. Now I want to display all comments and order them by votes-sum. Sum because some votes can have a higher value than others. Therefore I want to display if the user ...
0
votes
1answer
59 views

API POST to save a new item in a Database via PHP & MYSQLI

Is this correct MYSQLI implementation? IS it safe from injection? IS the object cleanup done properly? ...
7
votes
1answer
40 views

Stack Exchange Data Explorer query to find upvoted questions with only downvoted answers

I have written a SQL query against the Stack Exchange Data Explorer that identifies answered questions with a positive score for which all the answers have a negative score (this was an answer to this ...
2
votes
2answers
27 views

CROSS JOIN solution for records “missing” from a link table

Use case: We have a simple two tables plus a link table setup using some modern RDBMS. For example: Hospital table (id, name, ...
1
vote
1answer
33 views

Select Queries From Parent-Child Tables Model

I have two tables (parent-child model): Loans & Transactions. Each Loan row has multiple Transaction rows. I want to select all rows from Loans together with most recent row from Transactions. ...
6
votes
1answer
39 views

Implementing EXCEPT functionality for social networking exercise

I am taking Stanford's Introduction to Databases Self-Paced online course. I have gone through the videos in the SQL mini-course, and I am having trouble completing the exercises. The following is ...