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

2
votes
1answer
24 views

SQL Nested Selects

I was wondering if there is a better way to do the nested selects so that the firstname and surname is only doing one select ...
7
votes
1answer
51 views

C++ SQL wrapper/Statement

Part 2: (Part 1) Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
7
votes
0answers
26 views

C++ SQL wrapper/Connection

Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
7
votes
1answer
30 views

Do you Connect with my Groove?

I'm new at groovy, and this is my first time writing a database connection script. It may seem like example code, but it is more like test code. It works as posted, and I'm planning to use this as a ...
1
vote
1answer
28 views

Pull data from database to generate XML files

I have the following script in Perl that does the following: Prompts user for time in epoch. If user enters '########', the query will look for all reports generated after that date/time. If user ...
-4
votes
0answers
45 views

Query building body depending on parameters in a foreach loop [closed]

Is there a better way to write this method in C#? I really want to refactor this method in order to make it more efficient, but don't know how to. This string is the body of a ...
5
votes
2answers
82 views

SQL procedure with cursor to check if values in table 1 are also in table 2

The problem is that I'm checking if result from cursor exists in CDN.ZamNag table for every iteration. Is there any better way to check if values in table 1 are ...
0
votes
1answer
25 views

Synchronizing two SQL Server database tables with the most recent changes to both tables

I'm very new to SQL, but I'm coding a C# program that interacts with a database. There's a master database on my computer, and there's a client database on my tablet. When I re-connect my tablet to ...
5
votes
2answers
126 views

Finding questions to answer - Part 2

I've refactored my previous question finder, and added multi-tag support, and support for searching for keywords in the question titles. Essentially, what it does is find questions that could be ...
2
votes
1answer
40 views

Backing up two tables using SQL transactions

I'm using a transaction statement in SQL Server 2012 for the first time. I want to insert Table1's data in Table1_Backup before ...
8
votes
4answers
1k views

Math quiz in PHP

I coded a math quiz in PHP in which a user selects radio buttons as their answer choices. I retrieve the data of these ten radio buttons using $_POST[]; However, I ...
8
votes
3answers
127 views

Automatic variable generation from data table

I am adjusting Fast Report to create some reports, and I have created a loop that runs through query results stored inside a datatable and assigns each TenantName ...
3
votes
1answer
148 views

Query SteamIDs for presence of an avatar

I have a table vanrust_corev2.tblPlayerLog that has approx 6.7k records, I also have a table in a different database ...
7
votes
1answer
91 views

OR vs UNION in message tables

I have a dilemma. I have a messages table containing fields id, sender, receiver, body I need to select all users a given user has had a conversation with. A ...
8
votes
2answers
116 views

Finding questions to answer

In light of the recent "SQL frenzy" of sorts in The 2nd Monitor, I decided to take a stab at writing my own SEDE query. Essentially, what it does is find questions that could be answered based on the ...
1
vote
1answer
24 views

Writing an SQL SELECT statement

I'd like to Select columns from Table 1 with a Row Filter, Select columns from Table 2 and join. This works but it's a bit verbose. I was wondering if there is a cleaner way to write this. ...
2
votes
1answer
27 views

Using view for repeated subquery on a large table

I have a large table with which I need to do some analysis. The table is a log of IPs: ...
2
votes
1answer
36 views

Restaurant booking subquery

I have two database table name called "tablestr table" and "restbookingtable": tablestr: restbooking: I want to retrieve bookingsection_id from the booking ...
16
votes
2answers
241 views

“How can I make this SEDE query better?” (bad title finder)

It was suggested on Meta for July 2015 Community Challenge to make a bot that can find questions with bad titles. I wrote this query to help others find examples to help them make write their code. ...
7
votes
3answers
234 views

Grabbing the previous 4 quarters

I'm curious if there is a way to slim down this code either with SQL or with C#. ...
17
votes
4answers
1k views

Top users under age 30, sorted by age, with rank

In the pursuit of SQL enlightenment, I wrote a quick SEDE query to display Rep, Age and Overall ...
8
votes
1answer
34 views

The opposite of CodeLess Questions query

What's the opposite of CodeLess Questions? Perhaps CodeOnly Answers? (Also known as code dumps.) Inspired by the opposite question, here's the opposite query: ...
0
votes
1answer
45 views

Using Stored Procedures in ColdFusion / Lucee

This is how I write all my database interactions now in Lucee: ...
10
votes
1answer
265 views

CodeLess Questions query

As part of an exercise by Jamal to clean up old questions on Code Review that have no code in them, I helped by writing this query on Stack Exchange Data Explorer: CodeLess Questions ...
3
votes
1answer
43 views

Parameterized Query in Access SQL

I am a beginner in Access SQL. I am in need of writing a parameter query for Access SQL and found a few tutorials and links for that but that wouldn't satisfy my requirement. DB: Access DB This ...
3
votes
2answers
89 views

Inserting a name into a database table

I want to ask you if my PHP code is safe enough. I don't know if I should escape special characters in string after regex validation: ...
2
votes
1answer
49 views

Loading a Model from a Database

As you will see from the code below, I have a base model. ...
4
votes
1answer
55 views

Saving a form to a database

I have a windows form application which uses a form for two different purposes. We use the form for both our handheld system and our in-house system. I would just like someone to review the code for ...
1
vote
1answer
43 views

Medical database design and queries optimization

I have created a MySQL database which will be used in a medical app, but I am pretty sure the design and the used queries can be improved, since I am new in database design. My biggest doubt is the ...
3
votes
2answers
197 views

Creating Sequential IDs

I'm using SQL Server 2014 with Visual Studio 2013. When I add a new record, identity column (seed 1, increment 1) "ID" increases by 1, and record added to the database. My table consist of two rows: ...
4
votes
1answer
113 views

SQL Injection - Validating user supplied input

I was assigned a task to fix the SQL injection flaw reported by a code analysis tool and I am not the original author of the code and I do have fair amount of knowledge on SQL. ...
3
votes
3answers
170 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 ...
3
votes
0answers
34 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 ...
0
votes
0answers
17 views

Create variable and use in one stored procedure

This finds a value via a stored procedure then runs a second process in the same stored procedure rather than calling a second stored procedure. When a call is 'simple' i.e. not Where x y then... I ...
6
votes
1answer
58 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
52 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
36 views

SELECTing percentage and count of votes

I have the following tables structures: ...
1
vote
1answer
35 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
91 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 ...
3
votes
1answer
61 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
50 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
43 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
31 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
39 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
34 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
50 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
92 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
1answer
141 views

SecureString as SqlParameter value without GC concerns

The purpose here is to make it easy to use sensitive data that is already in the form of a SecureString (example) without converting it to a ...
5
votes
2answers
47 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
45 views

Perform SELECT INTO Statement and add Primary Key afterwards

How can I improve this TSQL Statement in terms of performance? ...