SELECT document_id
FROM table
WHERE tag = 'tag1' OR tag = 'tag2'
GROUP BY document_id
HAVING COUNT(DISTINCT tag) = 2
Edit:
Updated for lack of constraints…
More Related Contents:
- Solutions for INSERT OR UPDATE on SQL Server
- MySQL query finding values in a comma separated string
- SQLite INSERT – ON DUPLICATE KEY UPDATE (UPSERT)
- How to update selected rows with values from a CSV file in Postgres?
- Strings as Primary Keys in SQL Database [closed]
- Can table columns with a Foreign Key be NULL?
- Deleting duplicate rows from sqlite database
- Decision between storing lookup table id’s or pure data
- How Can I use “Date” Datatype in sql server?
- How to replace a string in a SQL Server Table Column
- How many rows in a database are TOO MANY?
- Primary key or Unique index?
- How to get a list of column names on Sqlite3 database?
- How to run a stored procedure in sql server every hour?
- Composite Primary key vs additional “ID” column?
- Questions every good Database/SQL developer should be able to answer [closed]
- Why do you create a View in a database?
- Logging ALL Queries on a SQL Server 2008 Express Database?
- Best database field type for a URL
- How to find rows in one table that have no corresponding row in another table
- sql unique constraint on a 2 columns combination
- SQL query to select distinct row with minimum value
- Oracle (Old?) Joins – A tool/script for conversion?
- sqlite select with condition on date
- ‘Lost update’ vs ‘Write skew’
- row-level trigger vs statement-level trigger
- How do I change db schema to dbo
- Query a Table’s Foreign Key relationships
- How to store a list in a db column
- Copy table structure to new table in sqlite3