May 2006
Monthly Archive
MySQL Examples31 May 2006 10:09 am
SQL Sub Queries
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;
MySQL Examples08 May 2006 10:43 am
MySQL DROP Command
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");
MySQL Examples08 May 2006 10:42 am
MySQL UPDATE Command
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");
MySQL Examples08 May 2006 10:42 am
MySQL INSERT Command
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) ");
MySQL Examples08 May 2006 10:40 am
MySQL DELETE Command
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");
Next Page »