Skip to content

Tag: sql

SQL Server: join data but in single row

I have a table Invoice that looks similar to this: order_id completed_at subtotal discount_amount handling_amount 100 07/01/2021 10.09 0 0 101 07/04/2021 200.30 0 0 102 07/04/2021 54.10 0 0 103 07/06/2021 12.00 0 0 And I have another table InvoiceDetail: order_id product_id qty amount 100 1234 1 1.09 100 Ship…

ActiveRecord having count query condition

I have 2 models : Conversation and Message I need to retrieve all conversations that belongs to a Brand and where there are at least one message from the brand and one message from an influencer This is my query : But i get conversations that doesn’t have messages from both… What am i doing wrong …

update join with where

I need to update a certain alert on a loan where the obligor and obligation is something, but I can’t figure out what I’m doing wrong in the join. This seems to update all alerts in the table rather than the specific one I want. We are using postgresql db Answer Workbench usually refers to MySQL. …

Data inserting in between the rows in table

I have a table which has around 1,000,000 records. I noticed that when I insert a record it does not get inserted at last instead it gets inserted in between Example My table (testing) Si. Name. Address. 1. Test. 1/2 test 2. Test. 3/4 test Si has a unique index created but no primary keys defined So when I ma…

Need help finding syntax error in SQL code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 9 months ago. Improve this question I have been trying to follow along with a SQL tutorial on YT. Every …

Accurate DateDiff

I have 2 time fields in SQL. I want to calculate the difference between start time and end time in hours. From 7 AM in the morning to 7:30 PM it would be 12.5 hours but the datediff function returns 12 hours because it returns an integer. I also tried converting it to seconds: All of these return 12 hours

MySQL: Error 1045 – how to set correct rules?

I have MySQL db and need to create a new database. However, I can not do it since I keep getting the 1045 Error. shows following: I don’t even have enough rights for rewoking and granting or creating a new user. Could you please help me what to do? Answer You only have privileges on a schema named db. Y…