I’m using Sequelize, and trying to learn from the queries it constructs. I have some complicated one-to-many relationship between few models, so i come across this query: The query itself is not important, but i would like to understand the meaning of the “->” operator, like in: ScrumList…
Tag: sql
Matching two values of different types in two SQL databases
I am trying to compare records between two different SQL tables/databases in my Node project and have to do some transformation in order to compare the values. In one database (MariaDB) the value is of type INT, and looks like this: 516542 In the other (SQL Server) database the value I need to match to is of …
SQL Server export image to hardisc by iterating through fieldnames
We receive 10 images in varchar format through a mobile device app which are stored in one record of a table. The fields where the images are imported are named ImportPictureData, ImportPictureData2,… more of the importfields could be added. To make the export flexible, I read the fieldnames in a table …
Android Studio Null object Reference
Creating an question/answer test application that scores you based on how many attempts it took to get it right (i.e on the first attempt 5 points, 2nd attempt 4 points… and so on) the questions are stored in a .DB file in asset folder and after testing the scoring logic I’m now trying to draw fro…
SQL statement to query new buyers on rolling basis
I currently have a order table that looks like this: I have been trying to create an SQL statement that will return something like this by doing a count(distinct user_id) : Of course, there will be multiple item_ids in the order table. What I’m trying to achieve is to obtain the rolling number of buyers…
SQL query for pagination with multiple columns; understand OR operator
I’m using a tool that generates the Postgresql query below: I need to understand why the OR operator? My players table can have many rows with the same score but not the same id. Is that OR needed when multiple rows has the same score value? Answer The purpose of the OR — as you suspect — is…
SQL Query with REGEXP to change URL strings dynamically
My DB table named “post” does look as follows So not every message row does contain an url and not every message with a [LINK]-tag does contain a proper url. Also there are enrties which have a longer ID, they should not be changed. Now i have to change every entry which has an ID length between 4…
The INSERT statement conflicted with the FOREIGN KEY constraint “FK__…”
I’m a very new beginner with SQL and I’m battling a problem I can’t seem to find the answer to. I’ve found similar questions here on Stack Overflow but I still can’t see what I’m supposed to change in my code to make it work. I’ve got 4 tables in a relation as follows…
replace a column with another column when column is null in SELECT statement
Here is my dummy Schema in MYSQL: A column: which is a nullable string B column: which is a string but its not null I only want to select A columns but when facing a null, I want it to be replaced with the B column. How can I do that? this is my desired output Answer Use coalesce():
How to generate an AR query that returns record A, excluding any that are attached to record B of a certain type
My relevant DB tables are an Invoices table and an Advances table with a has_many relationship (an invoice has many advances). I am trying to generate an ActiveRecord query that will return all …