I have three tables, with these fields: classes: class_id | name | grade classes_students: class_id | student_id students: student_id | name Classes has a 1:n relationship with Students, so one …
Tag: mysql
Meaning of “Select tables optimized away” in MySQL Explain plan
What is the meaning of Select tables optimized away in MySQL Explain plan? explain select count(comment_count) from wp_posts; +—-+————-+—————————+———————…
Join 2 Tables and display everything
I have 2 simple tables: table a: id | txt —+—- 0 | aaa 1 | bbb 2 | ccc table b: id | tel —+—- 0 | 000 2 | 111 I am trying to join 2 tables like this: SELECT a.*,b.* FROM a,b …
MySql – Way to update portion of a string?
I’m looking for a way to update just a portion of a string via MySQL query. For example, if I have 10 records all containing ‘string’ as part of the field value (i.e., ‘something/string’, ‘…
What’s wrong with my SQL query?
I need a quick look at my SQL query. It’s already given me a headache. Comparing some advice I have gotten, I could not figure out the proper format for my SQL. This is my code: Thanks in advance! EDIT: Currently I have this as the form: This is the insert query: Seems to submit the entry, but not the
sort the “rollup” in group by
I found that the “with rollup” option used with group by is very useful. But it does not behave with “order by” clause. Is there any way to order by the way I want as well as calculate the sub-totals? …
MAX on columns generated by SUM and GROUP BY
I’m trying to get the MAX on a column which is generated dynamically using the SUM statement. The SUM statement is used together with the ‘GROUP by’ syntax. This is the original query, however it needs to be modified to work with grouping, sums and of course MAX. As you can see SUM is adding all the values inside video_plays
How can I print the SQL query executed after Perl’s DBI fills in the placeholders?
I’m using Perl’s DBI module. I prepare a statement using placeholders, then execute the query. Is it possible to print out the final query that was executed without manually escaping the parameters and dropping them into the placeholders? Thanks Answer See Tracing in DBI. The following works using DBD::SQLite but produces a lot of output: Output: <- prepare(‘SELECT … FROM
Best way to test if a row exists in a MySQL table
I’m trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this: SELECT COUNT(*) AS total FROM table1 WHERE … and check to see if the total is non-zero or is …
Can MySQL replace multiple characters?
I’m trying to replace a bunch of characters in a MySQL field. I know the REPLACE function but that only replaces one string at a time. I can’t see any appropriate functions in the manual. Can I replace or delete multiple strings at once? For example I need to replace spaces with dashes and remove other punctuation. Answer You can