Skip to content

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…

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…

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

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)