How do I get SUM function in MySQL to return ‘0’ if no values are found?

Use COALESCE to avoid that outcome.

SELECT COALESCE(SUM(column),0)
FROM   table
WHERE  ...
Advertisements

Error: Duplicate entry ‘1-‘ for key ‘whosonline’

Backup your database then try doing a repair and optimize on your database and see if that helps. If you do not know how ask your Host to do it.

PhpMyAdmin Tutorial: Repair and Optimize Database

Sometimes the database tables get crashed. Also, they should be optimized from time to time. In this part of our PhpMyAdmin tutorial we will show how to repair and optimize database tables through PhpMyAdmin.

How to Repair MySQL Database Tables?

Open the database which should be repaired.

Select the tables that need repair and pick the Repair table action from the drop-down menu located below the tables’ list.

The tables will be repaired and you will get a confirmation screen.

How to Optimize MySQL Database Tables?

Open the database which you want to optimize.

Select the tables that need optimization.

From the drop-down menu pick the Optimize table option.

After the tables’ optimization a confirmation message with a list of the optimized tables will be visualized on the screen.

example for create sequence and trigger in oracle

create table test_b(
u_id integer not null primary key,
u_name varchar(30) not null
)

CREATE SEQUENCE test_b_seq
MINVALUE 1
MAXVALUE 9999999999
START WITH 1
INCREMENT BY 1
CACHE 100;

create or replace TRIGGER trigger_airports
BEFORE INSERT ON airports
FOR EACH ROW
BEGIN
SELECT airport_seq_id.nextval
INTO :new.u_id
FROM dual;
END;

insert into test_b(u_name)values(‘bapu2’);

create or replace TRIGGER test_after_insert AFTER INSERT ON test_b
FOR EACH ROW
BEGIN
insert into test_emp_backup values (:new.u_id, :new.u_name);
END;

select * from test_b;

select * from test_emp_backup;