Skip to content

Instantly share code, notes, and snippets.

@simongcc
Last active July 8, 2020 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongcc/d4d37cbe4e597154b26394ce715359c6 to your computer and use it in GitHub Desktop.
Save simongcc/d4d37cbe4e597154b26394ce715359c6 to your computer and use it in GitHub Desktop.
mysql-notes

// reset table id from 1 ALTER TABLE tablename AUTO_INCREMENT = 1

MySQL multiple columns in IN clause https://stackoverflow.com/questions/44706196/mysql-multiple-columns-in-in-clause (x0, y0, x1, y1) IN ((4, 3, 5, 6),(9, 3, 2, 1))

for string, need to be ... IN ('something1', 'something2') ...

able to search taxonomies with specific keywords, this is part of the clause

remove or exists() works separately

OR EXISTS ( SELECT DISTINCT t., tt., tr.* FROM ".$table_prefix."terms AS t INNER JOIN ".$table_prefix."term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN ".$table_prefix."term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'person-types') and t.name like '%".$tag."%' )

Query Time for reference SELECT DISTINCT pm.* FROM something_postmeta AS pm 0.0002s

SELECT SQL_CALC_FOUND_ROWS something_posts.* FROM something_posts WHERE 1=1 0.0012 seconds

SELECT something_posts.* FROM something_posts WHERE 1=1 0.0006 seconds.

SELECT something_posts.* FROM something_posts WHERE ID > 100 LIMIT 10;

Research

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment