Skip to content

Tag: sql

Canonical way to store reciprocal data sql

I got a lot of instances of the same Class. Now these objects can be linked and this link can have a weight. Like in an undirected graph. Now I want to store the relationship between each two objects in my mysql database. Data looks like this I could do create a table with this structure: object1_id | object2…

Using the Union function in SQL to reverse columns

I have the following SQL code to produce the following table of data: I am hoping to transform data to create a table that looks like: What would be the best way to achieve this? Something like creating two tables and then a Union join? Answer You can use self join to achieve what are you looking for. Schema:…

Update SQL database registers based on JSON

I have a table with 30k clients, with the ClientID as primary key. I’m getting data from API calls and inserting them into the table using python. I’d like to find a way to insert rows with new clients and, if the ClientID that comes with the API call already exists in the table, update the existi…

Multiple dynamic FIND_IN_SET searches

So, I have an array like this in my programming language: And I have a MySQL database table like this: Unfortunately, I cannot change the table to be more relational (yet). I want to pull out how many times an item in my array is present in the database value column. Now, the obvious way to do this would be