Для получения полного доступа
зарегистрируйтесь.

Section:
Sub-section::
Languages:


samdark
  • Reputation: 349
  • Snippets: 57
  • Revisions: 5

The query is an efficient way to get 10 latest comments limiting it to maximum one comment per post.

SELECT *
FROM comment c1
LEFT JOIN comment c2 ON c1.id < c2.id AND c1.post_id = c2.post_id
WHERE c2.id IS NULL
ORDER BY c1.id DESC
LIMIT 10
samdark
  • Reputation: 349
  • Snippets: 57
  • Revisions: 5
SELECT *
FROM news
WHERE id IN (2, 10, 3, 88, 23)
ORDER BY FIELD (id, 2, 10, 3, 88, 23)
samdark
  • Reputation: 349
  • Snippets: 57
  • Revisions: 5

Very useful in case when foreign constraints aren't working.

SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA='my_db_name'
AND TABLE_TYPE='BASE TABLE'
AND ENGINE IN ('MARIA','MyISAM')