Assume I have such table OrderLineID OrderID ProductID OrderedQunatity 1 1 2 18 2 1 10 9 3 2 3 12 …
SQL script behaves differently when run from PHP
I have about 5 million records in a database table (MySQL 5.6), and I wanted to get the last 2 dates, grouped by ID. Looking around the web, I found examples that allowed me to cobble together the following… Running this code from MySQL Workbench, returned 5,700 rows, which is what I expected. I then tr…
Many to many with pivot data to dgraph using graphql schema
I have the bellow many to many relation using a relational DB and I want to transition this to the dgraph DB. This relation has also extra columns in the pivot table: products_stores like price, …
INNER JOIN and Count POSTGRESQL
I am learning postgresql and Inner join I have following table. Employee Department I want to query to return the Department Name and numbers of employee in each department. I dont know what I did wrong as I am new to database Query. Answer When involving all rows or major parts of the “many” tabl…
BigQuery: Best way to ORDER BY an arbitrary GROUP BY expression when that expression is not in the SELECT clause?
In the below query, I want to group all orders by the concatenation of firstname and lastname, and order the result set by that concatenation. I do not want to include the concatenation in the SELECT column list. BigQuery returns the following error for the query: ORDER BY clause expression references column …
BigQuery: Best way to ORDER BY an arbitrary GROUP BY expression?
In the below query, I want to group all orders by the concatenation of firstname and lastname, and order the result set by that concatenation. However, BigQuery returns the following error for the query: ORDER BY clause expression references column [column_name] which is neither grouped nor aggregated I can f…
Do I need to set XACT_ABORT to ON in every trigger?
This was an old SQL Server 2008 Express database (five of them actually) that I just migrated to SQL Server 2019 Express. Everything seemed to be working fine until my crew got in and we were getting an error everywhere. Turns out we had RAISEERROR in the triggers, and even though my compatibility appears to …
Updating Status when there is a duplicate
How can I update my status to 1 if the condition is same Reference, but 1 reference should be Debit and 1 credit. If they are 3 records with same Reference but 2 with same debit amount and 1 credit 2 records should be updated to 1 that is 1 with credit and 1 with Debit using SQL Answer Looks
How do I write a condition within an SQL Select statement
I have a rather long SQL query to pull some values out my database written inside a stored procedure. I am passing an IN parameter called pupiltype which will either =0 or =1. If the pupiltype value=1, I need the line a line in my query to be: but if the pupiltype value is 0, it needs to be: I
lock and get next n records from table in oracle
I have a oracle table PHONE_NUMBER which has 2 columns PHONE and STATUS U stands for used , O is open/UnUSED . in my input I will get n as input number , which signifies the number of phones I want to reserve(update status to U from O ) I want a query that will lock(something like SELECT FOR UPDATE)