I’m trying to use a Left join query to get the last three results. If the user types in “carl” in the search field, it should return from Mysql carl, rick and peter because they have the same “pid” and they are below carl in the table.
SELECT parent.*
FROM mytable parent
LEFT JOIN mytable child
ON parent.pid = child.pid
WHERE name LIKE '%carl%'
ORDER by `id` ASC;
+----+----------+------------+
| id | pid | name |
+----+----------+------------+
| 1 | null | dave |
| 2 | 1 | mike |
| 3 | 1 | carl |
| 4 | 1 | rick |
| 5 | 1 | peter |
I get this error “Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource…” when i try the query above.
Do child/parent has a “name”,”id” column?
Change it something like:
Regards