Just need some help with a SQL statement, I have a table that has a bunch of user data, currently I am getting all the data by rowid descending. However I need to modify the way the data is displayed as follows:
The table has a field in which users can specify their own value or the can choose the default value. When choosing the default value the field is auto populated with a “randomstring_standardefaultvalue”.
So basically I need to select all the data in which the user did not choose the defaultvalue and have them order descending and then grab all the rows in which the user selected the defaultvalue and populate them after the first set of data sorted by descending rowid.
My current SQL Looks like this,
$query = "SELECT * FROM userform ORDER BY _rowid_ DESC LIMIT {$offset}, {$pl};";
Table Data:
rowid date username defaultoruniquevalue member etc...
Help would be greatly appreciated.
Thank You!
ANSWER:
SELECT *, IF(defaultoruniquevalue LIKE CONCAT('%','defaultstring','%'), 1, 0) AS uses_default
FROM table
ORDER BY uses_default ASC, _rowid_ DESC
LIMIT {$offset}, {$pl
I hope I’m understanding your question correctly, but it sounds like you need to add a WHERE clause to your query:
Edit