Wednesday, 11 April 2012

Mysql delete all pending wordpress comment


If you know yourself around phpMyAdmin and MySQL queries, just run this one line query in the “Sql Query” window of your WordPress database in phpMyAdmin. This query instantaneously deletes all comments in “pending” status. All your approved comments won’t be touched. To be on the safer side you may also want to backup your entire database or just wp_comments table just in case something goes wrong.
1. Open your WordPress mysql database in phpMyAdmin.
2. Find out the name of your WordPress comments table (mostly it is “wp_comments”).
3. Click on the “SQL” tab at the top of the page.
4. Insert the following mysql command to the text box and click “Go”.
DELETE FROM wp_comments WHERE comment_approved=0

Saturday, 7 April 2012

Create Table Example

CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

CREATE DATABASE Example


CREATE DATABASE Example

Now we want to create a database called "my_db".
We use the following CREATE DATABASE statement:
CREATE DATABASE my_db
Database tables can be added with the CREATE TABLE statement.

SQL UNION Example


SQL UNION Example

Look at the following tables:
"Employees_Norway":
E_IDE_Name
01Hansen, Ola
02Svendson, Tove
03Svendson, Stephen
04Pettersen, Kari
"Employees_USA":
E_IDE_Name
01Turner, Sally
02Kent, Clark
03Svendson, Stephen
04Scott, Stephen
Now we want to list all the different employees in Norway and USA.
We use the following SELECT statement:
SELECT E_Name FROM Employees_Norway
UNION
SELECT E_Name FROM Employees_USA
The result-set will look like this:
E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Scott, Stephen
Note: This command cannot be used to list all employees in Norway and USA. In the example above we have two employees with equal names, and only one of them will be listed. The UNION command selects only distinct values.

SQL UNION ALL Example

Now we want to list all employees in Norway and USA:
SELECT E_Name FROM Employees_Norway
UNION ALL
SELECT E_Name FROM Employees_USA
Result
E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Svendson, Stephen
Scott, Stephen

SQL FULL JOIN Example


SQL FULL JOIN Example

The "Persons" table:
P_IdLastNameFirstNameAddressCity
1HansenOlaTimoteivn 10Sandnes
2SvendsonToveBorgvn 23Sandnes
3PettersenKariStorgt 20Stavanger
The "Orders" table:
O_IdOrderNoP_Id
1778953
2446783
3224561
4245621
53476415
Now we want to list all the persons and their orders, and all the orders with their persons.
We use the following SELECT statement:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
FULL JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
The result-set will look like this:
LastNameFirstNameOrderNo
HansenOla22456
HansenOla24562
PettersenKari77895
PettersenKari44678
SvendsonTove 
  34764
The FULL JOIN keyword returns all the rows from the left table (Persons), and all the rows from the right table (Orders). If there are rows in "Persons" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Persons", those rows will be listed as well.

SQL RIGHT JOIN Example


SQL RIGHT JOIN Example

The "Persons" table:
P_IdLastNameFirstNameAddressCity
1HansenOlaTimoteivn 10Sandnes
2SvendsonToveBorgvn 23Sandnes
3PettersenKariStorgt 20Stavanger
The "Orders" table:
O_IdOrderNoP_Id
1778953
2446783
3224561
4245621
53476415
Now we want to list all the orders with containing persons - if any, from the tables above.
We use the following SELECT statement:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
RIGHT JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
The result-set will look like this:
LastNameFirstNameOrderNo
HansenOla22456
HansenOla24562
PettersenKari77895
PettersenKari44678
  34764
The RIGHT JOIN keyword returns all the