I have used transaction with try-catch block in my procedure. If any exception occurs, I am rolling back the transaction and after that trying to update a Results (Status) table. But, it looks like the Update statement is locking table (The Select query on that table is not working after that). Could you plea…
Tag: sql
Are indexes on columns with always a different value worth it?
Does creating an index on a column that will always have a different value in each record (like a unique column) improves performances on SELECTs? I understand that having an index on a column named ie. status which can have 3 values (such as PENDING, DONE, FAILED) and searching only FAILED in 1kk records wil…
How to determine a percentage gain or loss for a series of people in a table in SQL
I’ve posted a few questions about a system I’m trying to write, and feel bad for asking so many questions. However, I’m still quite new (or revisiting from years ago) to the finer elements of SQL …
SQL Server How to get number of unique values in a column and average score per values?
I have a table like this and so on What I ve done I got distinct count for every city and avg metric value But it is false Appreciate any help updated There is also an additional column id in varchar format Answer The answer here depends on this assumption: You always have exactly 3 metrics per ‘group&#…
I wonder using INNER JOIN and equality operator is faster or using IN when I try to filter data from a table by another table’s column
While I’m trying to get all accounts, which received message from foo@gmail.com. I want to know about the performance of two following query. or Thanks! Answer Always use the first query in such situations. Don’t use DISTINCT inside an IN clause subquery, though. Don’t try to tell the DBMS h…
SQL – Select using attributes from two tables
I am having an issue in extracting data using data of two tables in SQL. This returns A, B, C, D where E in T2 is not ZZZ. However, when I add another where clause like below, it returns data where T2 is ZZZ also. This ignores “T2.E <> ‘ZZZ’” part, but “D<>0” is not i…
How to Use a Subquery in MySQL in the Where clause that is an argument to an OR operator?
I am trying to filter a table for specific markets by using a subquery. I want to include all null values and exclude the markets that are included in the subquery. This query isn’t filtering out the markets I want to get rid of. And this created a SQL compilation error. When I list the markets I want t…
Migrate data from SQL Server to PostgreSQL
I have a stored procedure function as well as table in the SQL Server enterprise 2014. I also have data in the table. Now I need same table and data in PostgreSql(pgAdmin4). Can anyone suggest to me the idea to migrate data to POSTGRESQL or any idea on creating the SQL script so that I can use psql to run
Variable not defined on VBA about socket
I’m making an edit to a project on VBA that uses a Socket to send information to a program on Netbeans on a specific server. I did not write the code. I’m trying to understand what the original programmer did. I have many forms, and a few send information with that socket. I’m trying to do t…
Oracle – Concatenate calculated number field with string field
In this case statement below, I want the result to be a string, either ‘n days’ or ‘n weeks’ based on the conditions in the statement. How can I concatenate the number generated from ABS(FLOOR(TRUNC(i.schedule_finish) – TRUNC(sysdate))) with a string (that is, ‘ days’…