If I have a table like this:
int VARCHAR int
----------------------------------
1 "U" 1
2 "A" 1
3 "B" 1
and I run a query through php’s mysqli like this:
$sql = "SELECT * FROM " . parent::GetTableName();
if ($current_user_only == TRUE)
$sql = $sql . " WHERE userID_FK=" . parent::GetUserID();
$result = $this->get_db_con()->query($sql);
if ($result == FALSE)
throw new Exception("SQL exec failed (". __FILE__ . __LINE__ . "): $this->get_db_con()->error");
while ($row = mysqli_fetch_array($result))
{
echo($row[1]);
}
I get an output like this:
2 "A" 1
3 "B" 1
1 "U" 1
That is the result seems to be sorted by the VARCHAR column. If I run the same query in SEQUEL PRO it gives me results in the order I’m expecting which is the order in which they are entered in the table.
Any ideas?
Short answer: there is none.
Long answer:
For MyISAM tables it’s the natural order, i.e. the order in which rows are stored on disk, which is usually the order of insertion. This can be modified by running
ALTER TABLE ORDER BYFor InnoDB tables it’s the order of primary key.