You need to use HAVING
, not WHERE
.
The difference is: the WHERE
clause filters which rows MySQL selects. Then MySQL groups the rows together and aggregates the numbers for your COUNT
function.
HAVING
is like WHERE
, only it happens after the COUNT
value has been computed, so it’ll work as you expect. Rewrite your subquery as:
( -- where that pid is in the set: SELECT c2.pid -- of pids FROM Catalog AS c2 -- from catalog WHERE c2.pid = c1.pid HAVING COUNT(c2.sid) >= 2)
Related Posts:
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- MySQL – Operand should contain 1 column(s)
- MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- MySQL create table if not exists and insert record only if table was created
- How do I use properly CASE..WHEN in MySQL
- How can I do a FULL OUTER JOIN in MySQL?
- MySQL query String contains
- What’s the difference between VARCHAR and CHAR?
- Case statement in MySQL
- How to declare a variable in MySQL?
- MySQL Cannot Add Foreign Key Constraint
- How to split the name string in mysql?
- How do I import an SQL file using the command line in MySQL?
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- mysql Foreign key constraint is incorrectly formed error
- How can I return pivot table output in MySQL?
- Compare dates in MySQL
- MySQL “WITH” clause
- MySQL Multiple Joins in one query?
- Error Code: 2013. Lost connection to MySQL server during query
- MySQL syntax for Join Update
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- how to drop partition without dropping data in MySQL?
- MySQL: Invalid use of group function
- MySQL combine two columns into one column
- Simple way to calculate median with MySQL
- Error 1046 No database Selected, how to resolve?
- MySQL Error 1264: out of range value for column
- Remove duplicate rows in MySQL
- How to SUM and SUBTRACT using SQL?
- Cast from VARCHAR to INT – MySQL
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- How do you force mysql LIKE to be case sensitive?
- MySQL – UPDATE multiple rows with different values in one query
- How to create a MySQL hierarchical recursive query?
- ERROR 1148: The used command is not allowed with this MySQL version
- Insert into a MySQL table or update if exists
- How to round down to nearest integer in MySQL?
- MySQL starts with searching issue
- Query to convert from datetime to date mysql
- Is it possible to GROUP BY multiple columns using MySQL?
- MySQL error: key specification without a key length
- Best way to test if a row exists in a MySQL table
- Check if MySQL table exists without using “select from” syntax?
- MySQL equivalent of DECODE function in Oracle
- mysql update column with value from another table
- The used SELECT statements have a different number of columns
- How to delete from multiple tables in MySQL?
- MySQL: Can’t create table (errno: 150)
- How to copy a row and insert in same table with a autoincrement field in MySQL?
- Join vs. sub-query
- Alternative to except in MySQL
- Equivalent of explode() to work with strings in MySQL
- ROW_NUMBER() in MySQ
- MySQL OPTIMIZE all tables?
- MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET
- MySQL – Get row number on select
- MySQL error: Unknown column in ‘where clause’
- How to truncate the text returned for a column in a MySQL query
- Using union and order by clause in mysql
- MySQL LIKE IN()?
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- Using group by on multiple columns
- Efficiently convert rows to columns in sql server
- Nested select statement in SQL Server
- Sql Server equivalent of a COUNTIF aggregate function
- SQL Query Where Field DOES NOT Contain $x
- How can I select the first day of a month in SQL?
- Warning: Null value is eliminated by an aggregate or other SET operation in Aqua Data Studio
- Oracle Apex column link from LOV values
- ORA-01861: literal does not match format string
- SQL Server Insert if not exists
- SQL Server: Invalid Column Name
- Unknown Column In Where Clause
- How do I reset a sequence in Oracle?
- SQL: Two select statements in one query
- What does Include() do in LINQ?
- SQL Server “cannot perform an aggregate function on an expression containing an aggregate or a subquery”, but Sybase can
- Get everything after and before certain character in SQL Server
- SQLite string contains other string query
- “#1067 – Invalid default value for ‘post_date'” when trying to reset AI after backup
- Inserting Post Meta From SQL
- WordPress SQL LIKE request doesn’t work for fields with special symbols
- SQL command to convert all tags in lowercase?
- How can I add a new row in a separate database when someone registers via WordPress?
- WordPress can I manually add columns in users table and display it in the default manage user plugin and registration form? [closed]
- WP MultiSite: Can’t select database error after changing to new domain
- $wpdb->get_var – What value is returned when zero records are found?
- Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
- Database SQL query error
- Inserting other fields to existing registration form in a WordPress theme
- Organising and completing posts (mark as read and hide)
- can’t delete a row from post_meta table
- SQL error on restoring database
- Creating a “forum” – showing last post or last commented post
- If meta_key exists then don’t select this post?
- Possible SQL injection. How to locate and fix?