Delete all record from table in mysql

17. May 2013

Delete all record from table in mysql

http://stackoverflow.com/questions/8091053/delete-all-record-from-table-in-mysql

TRUNCATE TABLE <table name>;

MySQL, SQL

MySql Subtract a table from another

16. May 2013

MySql Subtract a table from another

I found this solution on - http://stackoverflow.com/questions/5738240/mysql-subtract-a-table-from-another

To view all rows in A except those in B:

SELECT*FROM A
WHERE(field1, field2,..., fieldN)NOTIN(SELECT*FROM B
);

To actually delete from table A the rows that are in B:

DELETEFROM A
WHERE(field1, field2,..., fieldN)IN(SELECT*FROM B
);

SQL ,

Query to verify case sensitive columns in SQL SERVER having Case insensitive Collation

2. March 2013

How to to verify case sensitive columns in SQL SERVER having Case insensitive Collation.

Use this query

SELECT * FROM LoginData WHERE username ='something' AND password COLLATE SQL_Latin1_General_CP1_CS_AS LIKE 'askjashAA';
OR

SELECT * FROM LoginData WHERE username LIKE 'something' AND password COLLATE SQL_Latin1_General_CP1_CS_AS LIKE 'askjashAA';

 

SQL ,

Query for getting the childtable no of rows related to one single row in parent table

28. February 2013
SELECT TOP 5 temp.totalcomments,NewsLetter.title,NewsLetter.nID 
FROM
(SELECT NewsLetter.nID,NewsLetter.title ,COUNT(a.nID) AS TotalComments
FROM NewsLetter LEFT OUTER JOIN (select nID from Comments where approved='true') as a
ON a.nID=NewsLetter.nID
GROUP BY NewsLetter.nID,NewsLetter.title) AS temp,Newsletter
WHERE scID=10 AND temp.nID=NewsLetter.nID AND trash='false'
ORDER BY totalcomments DESC;

SQL