Archive for ◊ May, 2006 ◊

31 May 2006 SQL Sub Queries
 |  Category: MySQL Examples  | Leave a Comment

A quick query structure to retrive the last row entry to a logging table, in this case there can be multiple rows that would return the same id and date but I want only the very last so this query works well.

[code]
$query="SELECT a.user_id, a.access_date FROM superlog a
WHERE a.access_date = (SELECT MAX(b.access_date)
FROM superlog b
WHERE a.user_id=b.user_id)
AND ip = CONVERT( _utf8 '10.10.10.10' USING latin1 )
COLLATE latin1_swedish_ci;
[/code]

08 May 2006 MySQL DROP Command
 |  Category: MySQL Examples  | Leave a Comment

The Drop command is used to delete all the records in a table using the table name as shown below:

Syntax:

$dropSQL=(“DROP tblName”);

Example

[code]
$dropSQL=("DROP tblstudent");
[/code]

08 May 2006 MySQL UPDATE Command
 |  Category: MySQL Examples  | Leave a Comment

The Update command is used to update the field values using conditions. This is done using ‘SET’ and the fieldnames to assign new values to them.

Syntax:

$updateSQL=(“UPDATE Tblname SET (fieldname1=value1,fieldname2=value2,…) WHERE fldstudid=IdNumber”);

Example:

[code]
$updateSQL=("UPDATE Tblstudent SET (fldstudName=siva,fldstudmark=100) WHERE fldstudid=2");
[/code]

08 May 2006 MySQL INSERT Command
 |  Category: MySQL Examples  | Leave a Comment

The Insert command is used to insert records into a table. The values are assigned to the field names as shown below:

Syntax:

$insertSQL=(“INSERT INTO tblname(fieldname1,fieldname2..) VALUES(value1,value2,…) “);

Example

[code]
$insertSQL=("INSERT INTO Tblstudent(fldstudName,fldstudmark)VALUES(Baskar,75) ");
[/code]

08 May 2006 MySQL DELETE Command
 |  Category: MySQL Examples  | Leave a Comment

The Delete command is used to delete the records from a table using conditions as shown below:

Syntax:

$deleteSQL=(“DELETE * FROM tablename WHERE condition”);

Example:

[code]
$deleteSQL=("DELETE * FROM tblstudent WHERE fldstudid=2");
[/code]