Insert If Value In Longtext Field Does Not Exist
Posted on 2005-04-04
I don't work with MySQL, so I'm not sure about the exact syntax of this.
What would be the most efficient way to insert a record that contains a longtext field of data into a table if the value of the longtext field does not already exist in the table? I'd like to compare the first 5000 characters of the two longtext fields with all spaces, line breaks, tabs, and carriage returns removed. The value checked and inserted will be coming from an html textarea.
I believe the general syntax should be:
/* need code to create a TempTable that contains a longtext field */
/* need to insert value, removed of all spaces, tabs, line breaks and carriage returns into the longtext field of the TempTable */
INSERT INTO TableName (LongTextFieldName)
SELECT LongTextFieldName FROM TempTable
WHERE NOT EXISTS (
WHERE SUBSTRING(TableName.LongTextFieldName, 1, 5000) = SUBSTRING(TempTable.LongTextFieldName, 1, 5000)
/* need code to do compare the substring of TableName.LongTextFieldName removed of all spaces, etc. */