Linked Questions
13 questions linked to/from count(*) and count(column_name), what's the diff?
-3 votes
2 answers
504 views
Is mysql count(*) much less efficient than count(specific_field)? [duplicate]
Possible Duplicate: COUNT() vs. COUNT(1) vs. COUNT(pk): which is better? count() and count(column_name), what's the diff? count(*) vs count(column-name) - which is more correct? The ...
429 votes
12 answers
503k views
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 it ...
0 votes
3 answers
757 views
SQL multiple CASE WHEN with same Count function
I have a record of students and I need to group them by age. I have this scenario: If Age group has only one member, display his/her name and sex Else Display 'SOME STRING' as name Check sex of ...
1 vote
3 answers
1k views
mysql COUNT(*) vs COUNT(DISTINCT col)
Q1: why count(*) is so much slower than count(distinct col)? Q2: should id always use count(distinct col)? select count(id) from source; +-----------+ | count(id) | +-----------+ | 22713 | +-----...
0 votes
3 answers
1k views
MySQL BEFORE INSERT trigger to turn duplicate primary keys inserts into updates
I'm trying to execute this query in a database through phpmyadmin create trigger avoid_duplicated_sharing before insert on sharingevents for each row begin if ( select count(*) from sharingevents ...
1 vote
1 answer
445 views
MySQL divide by values from 2 subqueries
The table structure is as follows: Players (PlayerID, FirstName, LastName, PositionID) Salaries (SalaryID, PlayerID, Amount) ScoredGoals (GoalId, PlayerID, GameID, Minute) Positions (PositionID, ...
4 votes
2 answers
65 views
Return list of member_number count in table
Consider the following table I need to return a list in descending order with the count of the member_nr's who is appearing the most frequent in the table where tournament = 'EPL' AND ROUND = '12' ...
0 votes
2 answers
327 views
Query most frequently purchased item's name based on ID occurrences in separate sales table
Need to identify the most frequent occurrence of an item ID from an item description table, match it to its corresponding ID on an item sales table, and then display only the name from the description ...
0 votes
0 answers
160 views
MySQL SELECT query in PHP not returning same results as querying database directly
I'm playing around with PHP. My issue is that my SELECT query with the COUNT() function is only returning one row, however when I query the database directly through phpmyadmin with what it echoes, ...
0 votes
2 answers
74 views
SQL: Sort on number of row entries and join
How do I find duplicate entries in a column (like multiple rows in student_id column) and join those to another table with common id (like student_id from another table to get student_name)? grades: ...
1 vote
2 answers
41 views
Query database to obtain first unique value
I have a pretty simple table like this: id | custom_id | answer ---------------------------------- 1 | 123 | Answer 1 __________________________________ 2 | 123 | ...
0 votes
1 answer
52 views
Call to a member function bind_param() on a non-object on SELECTION statement
I'm using the following code snippet to select number of rows from students table. But it shows the error "Fatal error: Call to a member function bind_param() on a non-object". In my table 'stacyear' ...
0 votes
1 answer
50 views
How to query with 2 fields?
I want to mysql query in a table that has 4 fields: id, user_one, user_two, hash. $check_con = mysql_query("SELECT count(hash) FROM messages_group WHERE (user_one=$my_id AND user_two=$other_id) OR ...