I have some problems with my trigger. On my transactions table I can’t allow any rows to be inserted which are cancelled. Any transaction can be Scheduled, Done or Cancelled. If you insert a cancelled …
Tag: sql
exists query does not return relevant result
I have a Laravel application with this Eloquent query: $products = Product::where(‘name’, ‘LIKE’, “%{$value}%”) ->whereHas(‘categories’, function($q) { $q->where( ‘slug’, ‘…
How to fetch data from first row to a particular row
I have two tables table 1 (log_audit table) table 2 is (final_log table) table 1 data looks like below table 2 data looks like below Here user “D” actual resolver of the customer ticket. …
String formatting issue for creating the SQL query for BCP
I want to use some of the static data to the new BCP query and export the extracted data to CSV. The static data are generated as a result after running some BCP command earlier. But I have been facing string formatting issue for creating the SQL query using those variables and generate a SQL command. I simpl…
DISTINCT work differntly in MYSQL & POSTGRESQL
I have created a sample table report in SQL and filled sample data in it using the following command. I need to find the list of recently visited(based on date column) branches with out duplication. So I used the following query It works on MYSQL but shows the following error on POSTGRESQL. How to fix this? O…
Need help understanding Postgresql query execution
I have a generated query from an ORM that selects data from a nested join on a junction table. When executing it looks like it performs a full table scan on a table with >55 million records resulting in a slow execution time. My expectation was that it would perform the filtering first then lookup by index…
Counting organizations which user has not contacted
I am new at PostgreSQL. I have the following tables created in my schema: User table: Organization table: And finally Organization_rating table: With this schema, an organization has a business type in which gives support to the user that also have that business type. After giving this support, the user can r…
ORA-01861: literal does not match format string use oracle SQL
I have data field in oracle database, i need to update my data field and use add_months function to add 3 more month as show below, my table name psm_voucher. then I try update query as below but fail Your kinds help is much appreciated. Answer As date in your table is stored as a string, you will need to
How to do a query on Oracle SQL to get time intervals, grouping by specific fields
I love a good challenge, but this one has been breaking my head for too long. 🙂 I’m trying to build a query to get dates intervals, grouping the information by one field. Let me try to explain it in a simple way. We have this table: I need to get the intervals a soldier spent on each ranking, so
Find closest match to value in another table
I have a table_a with many rows and columns for each timestamp in PostgreSQL 13. I’m trying to find the row where the value in column X is closest to a benchmark value obtained from another table. This second table has only a single benchmark value for each timestamp. For each timestamp, I need to retur…