I have two tables, which look roughly like this: I want to query these tables to return only the customers who are in both tables, but also to only return the rows where that combination of customer & offer does not exist in table2. In other words, the results should look like this: Does anyone know how b…
Tag: sql
sql join without intermediate table (old database)
I’m working with a really old database and I’d like to do a simple join. Unfortunately, there is no intermediate table and it’s not possible to implement it in the near future (I know it’s really bad). The tables look like this: Expected result (for tbl_1.id = 1) How can I achieve that…
Compare rows in one table with MySQL
I tried to compare rows in one table that I have. The table is like this: table I have 3 rows for comparing, and they had tp 1,2,3 for each one with the same fid and different id. The question is, how can I compare three of them to return? For example, more explanation For example, if ct of the
RawSQL and auto-generated keys in EF Core 3.1
I have a Model with a Guid primary key. I want the Database to generate a key on insert so I added the following annotations: Now I expected that inserts with RawSQL wouldn’t expect a primary key, however the folllowing statement doesn’t work when executred through ExecuteSqlRaw: An error is cause…
PostgreSQL – How to format an int as an hexa
What’s a short/simplest way of formatting an int to an hexa, with leading zeroes? For example I need to format: My query needs many of these conversions I would appreciate a short piece of code instead of a verbose one. Just need to deal with positive numbers. Answer I’m not sure it’s the sh…
SQL add a * to front and back
Need to add a * to the front and back of the results in order to be able to export it via report builder and use barcodes fonts. Example *1234* My query is My result is I am looking for Answer Use concat():
Calculate Days Between Based on 3 Variables & Syntax Error
I’m hoping you can provide some insights on a couple of issues: ISSUE 1 – i’m receiving the following error message running in Teradata: “Syntax error, expected something like ‘)’ between an integer and the ‘then’ keyword.” There are some duplicate records…
SQL remove leading zeros
I am unable to remove the leading zeros from a column. In this case my SQL query is The result is I am looking for this result. Answer Use the floor() function: Why are you storing these values as strings in the first place? You should be storing numbers as numbers. And if they are numbers, you should not be
How to loop through JSON array to insert rows in SQL Table using TSQL?
I have following query where I would like to insert data from JSON: INSERT INTO EncExt ( reference ,system ,code ,display ) SELECT JSON_VALUE(record, ‘$.id’) AS reference , JSON_VALUE(…
Adding a calculated column while joining tables in Snowflake
I have 4 tables A, B, C and D with 3 columns each A- aa, ab, ac B- ba, bb, bc C- ca, cb, cc D- da, db, dc I need to join the 4 tables and add a new calculated column (aa + ab + ac). My query …