Questions tagged [sql]

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.

Filter by
Sorted by
Tagged with
2
votes
0answers
27 views

Insert data from one table to another (million+ rows)

I have a procedure that collects data from one table and inserts it into another table with the same columns, but after correlating with a few other tables. Since the existing table (from which data ...
3
votes
0answers
41 views

MySQL JSON diff procedure

I'm building a procedure which compares two JSON objects and return two JSON objects with differences between each (compared keys and values). But I have relatively superficial SQL knowledge, so I ...
0
votes
0answers
19 views

Dynamic “compilation” of SQL stored procedures

I have a stored procedure which is called to create ( "compile" ) temporary stored procedures, code below, based on whether a flag in a database record is set - the various sub-procedures such as ...
0
votes
0answers
26 views

Tracking when a column was last modified using a trigger (in SQL Server)

How can I improve the following code to track when an Azure SQL Database column value was last modified? ...
0
votes
2answers
54 views

Improving/ Optimizing Performance Query in MySQL PHP

I have invoices, invoices_items, order, order_items. <...
1
vote
0answers
54 views

Helper class for ASP.net to return data from SQL server

My goal is to create a class that I can call from my webpages like this. Similar to a data access layer? ...
2
votes
0answers
53 views

SQL Database for Visitor Registration System

This is intended for a web-based application that allows someone to register visitors, assign their hosts, and indicate the dates in which they will be visiting. Imagine this scenario: I want to ...
1
vote
1answer
76 views

PHP code for search page

Want to show you part of code that I wrote to process search request. User commit search by articles (codes) of products. The goal is to allow user write his search request to textarea element in any ...
0
votes
0answers
7 views

MySQL insert record to one table to another if postid is not exist

Is there any way to write this query in a better way than this if I want to insert postid from posts table to ...
1
vote
0answers
23 views

SQL self-join to label nodes on binary search tree

Would like feedback on my SQL (1) efficiency and (2) readability, and if the conditions I featured in my CASE statement could be transferred to a join, etc. Here'...
2
votes
1answer
76 views

Build a string for a search query

I am building a string for a search query and I think I am doing it the wrong way. So basically I have serveral textfields, dates, integers and so on in one form. On submit I am checking the forms if ...
0
votes
0answers
16 views

Window function in MySQL 8

I'm running the following query on my database: ...
0
votes
0answers
76 views

Using an N-Tier architecture for a dynamic CRUD user control system

I want to design a flexible dynamic system for a client with standard data-entry screens and CRUD UserControls I dont know whether ...
2
votes
2answers
69 views

ORM class for Posts

I'm new to PHP OOP and I'm making some tests. I have 2 classes: database and posts and the two interact with each other. Class Database: ...
0
votes
2answers
24 views

Bulkloading xml's into Oracle table

Intro We have some old(in my eyes) software at the place I work at the moment, Some stuff needs to be done manually, for instance we need to insert a XML file into a Oracle table, which will trigger....
2
votes
0answers
32 views

Get local datetime from UTC time

One of the app is inserting date in UTC format (column CreateDate). When reporting from this table, I used a difference in hours between the inbuilt ...
0
votes
1answer
91 views

Modify a column in 2 tables based on trigger

This is SQL Server 2008r2. First, here are some tables and data for test: ...
2
votes
2answers
131 views

Add variable columns to INSERT statement

I'm learning SQL using python library pymysql. I wanted to make an INSERT statement that will update 3, 5 or 10 columns using the same code by just passing the ...
1
vote
0answers
22 views

Calculate BACKLOG_M_1

I need to calculate the BLACKLOG_M value corresponding to the Snapdate of the first of the month. It becomes a constant value repeated for each line of the month As it is explained in the picture: <...
0
votes
0answers
168 views

Doctrine Query with subquery

I'm wondering if this is the right way to have a subquery in Doctrine. I have two entities, one called User and one called Log. ...
1
vote
0answers
120 views

Syncing a table to a remote database

I want to sync the table every few minutes to a remote database. I want it to be as efficient as possible. I wrote this stored procedure that will only return rows that are added or removed after the ...
0
votes
1answer
45 views

Validating region/state/province codes for different countries

I have a large table in which I store region/state/province codes (two letters) from different countries. I use these region codes further downstream for multiple process. One of the steps I do is a ...
5
votes
1answer
132 views

Polymorphic Data Socket Factory with Query Contingency Protocols in Python

I work on a small data team where we developed this tool when we began experiencing several job failures on our legacy big data systems. We have several data lakes, each with their own API, and until ...
2
votes
0answers
909 views

MySQL database schema for e-commerce website

I'm making an e-commerce site, using MySQL for storing data. ...
3
votes
1answer
33 views

Iterate between dates and INSERT values in a performant way

I have created a query that populates a datapoint with random values. The logic is simple: Iterate between the START and END dates and INSERT random values. I want from this query to be very ...
3
votes
1answer
124 views

SQL SP creating certificates for shipping

We ship large spools of copper wire and pallets of copper rod that have to meet specific chemical and mechanical requirements, this is what must be put on the certifications. I created an SP which ...
3
votes
1answer
60 views

Generating report columns from SQL query

I've written this class to create RapportColumn objects for each column that is written in the query. And I would like to get your feedback. The query that is ...
2
votes
1answer
80 views

New comments after a user's last comment

Edit: I've added everything I can... I have the following query, which gets the last comment from the user in a given topic, then I check in the while loop if there are newer comments. My problem is,...
3
votes
1answer
46 views

Static class for database access Java JDBC

I'm writing a small program to store data in a database (a discord bot mainly). I know cleaner ways of using dependency injections and DAO exist, but I haven't written a DAO (or the user class) and ...
2
votes
0answers
34 views

SQL query that extracts a topic keyword from article titles

I have a query like this to select the only row with title contains specific programming topics. ...
0
votes
1answer
33 views

Get chat message data from table, grouped by date

Giving the following table: ...
3
votes
1answer
134 views

PHP + PDO - Inserting data on the table with a loop

First of all i made a simple code to insert data on my table, with the information from this code i made a loop to insert data on another table for a notification system. I'm new to PHP and i think ...
1
vote
2answers
368 views

Using decorator and strategy pattern for dynamically generating SQL queries

This is a link to my application that actually runs on the design specified in the image. The idea behind the image is that the SubjectInfoViewer behaves as the ...
2
votes
2answers
461 views

Find all shortest paths between 2 nodes in a directed, unweighted, SQL graph

I want to find all shortest paths between a pair of vertices in a unweighted graph i.e all paths that have the same length as the shortest. The edges of the graph are stored in a SQL database. The ...
1
vote
0answers
21 views

Activity grouping and selection according to order and completion requirements

The problem consists of two categories of events (Work and Rest) which together form a complete set. The number of Work events is open-ended. The number of Rest events is fixed at three (3). The ...
2
votes
0answers
279 views

Simple web API that access sqlite database

This is a very simple web API for a school assignment, as a part of a bigger system. The web API returns a list of courses or a single course as json. I doubt that I will get any feedback on the code ...
2
votes
0answers
79 views

Upsert query using CTE in PostgreSQL 9.4

I have a generic pipeline in SnapLogic that logs the start time of the executions of a group of incremental jobs. Suppose, the log table is as follows. ...
0
votes
1answer
49 views

Updating 3 columns conditionally on a database table

I need to run this script to update the value of 3 columns based on certain conditions. Right now, this is what I have: ...
0
votes
1answer
70 views

Simple PHP project to store inputs in MySQL and output them

As my first simple PHP project, I've created a simple project that allows you to just enter your name and two numbers, where it displays them on the page and stores them in a database. It consists of ...
3
votes
0answers
32 views

SEDE query to calculate net migrations quarterly from ELU to ELL

Over on EL&U Meta, someone raised the question of how many net migrations there are to/from our sister site, ELL. The following SEDE query calculates the net migrations by quarter (...
0
votes
0answers
16 views

Dynamic Statement Evaluator

I've written a stored procedure in order to simplify the process of calling dynamically constructed MySQL statements: Implementation ...
1
vote
0answers
248 views

Kotlin DAO with Exposed: How to reduce redundancy in classes?

I'm writing a Kotlin app that uses Exposed (https://github.com/JetBrains/Exposed) as a SQL wrapper to write and read objects from databases. The problem I'm facing is that I end up with 3 classes ...
1
vote
1answer
44 views

Loop Through bitarray to retrieve subsets of that bitarray

Objective: I want to loop through a bitarray and store subsets of that bitarray in a table. Context: I have a bitarray with 48 elements where each element represent one hour. I want to look back 24 ...
2
votes
1answer
83 views

Repository of trainers

This is my first asp.net core web api and i did followed the Repository pattern but i don't know whether this approach is good practice. ...
3
votes
1answer
176 views

Inserting data into SQL-Server table dynamically

I know I can do all this via SSMA quite quickly, but I wanted to see if I could do it efficiently in PowerShell myself as a little project. Basically, the entire script takes tables from an Access ...
-5
votes
1answer
81 views

How to write SQL in a industry standard style [closed]

Here are the commands I ran to start setting up a database I need. ...
2
votes
0answers
33 views

SQL query for selecting count from grouped columns of latest records

I have this table on SQL: ...
1
vote
2answers
129 views

Use a comma-separated field in another SQL query

I was just wondering if there was a better way to write this block of code in php. I have a string with values separated by commas. I need to prepare that string to pass it on to the query using IN ...
1
vote
1answer
58 views

Insert data on Data Base using PDO Prepared Statement

...
2
votes
2answers
89 views