SQL select rows with only a certain value in them
SELECT col2
FROM your_table
GROUP BY col2
HAVING MAX(col3) = 1 AND MIN(Col3) = 1
Or
SELECT a.col2
FROM your_table a
WHERE a.col3=1 AND NOT EXISTS(SELECT *
FROM your_table b
WHERE a.col2=b.col2 AND b.col3<>1)
SQL query to select rows where a column contains only specific values
Using aggregation, we can try:
SELECT id
FROM identities
GROUP BY id
HAVING MIN(child) = MAX(child) AND MIN(child) = 200;
The first condition of the HAVING
clause asserts that a given id
group of records has only a single child
value. The second condition asserts that this single value is 200.
SQL select the only rows with only a certain values in them
You can use conditional aggregation
for this:
select col2
from yourtable
group by col2
having sum(col3=1) > 0
and sum(col3=2) > 0
and sum(col3 not in (1,2)) = 0
- SQL Fiddle Demo
SQL select rows that have one specific value but not another in the same table
This should work in any RDBMS:
select DOC from table_name
where DEPARTAMENT = 'DEP 1'
and DOC not in
(select DOC from table_name where DEPARTAMENT <> 'DEP 1');
You can use MINUS
or EXCEPT
if your RDBMS supports those.
SQL query to get specific rows based on one value
SELECT *
FROM FullResults
WHERE ID = (SELECT ID
FROM FullResults
WHERE Type= @variable);
I guess it will be something like this?
How can I get specific rows in a table by the value of a specific queried column of a different table?
If I understood your question correctly then you can try this
SELECT * FROM table2 WHERE IC = (SELECT IC FROM table1 WHERE B='B1')
Related Topics
Is Varchar(Max) Always Preferable
How to Compute Tf/Idf with SQL (Bigquery)
How to Write SQL Using Speech Recognition
SQL Update Statement to Switch Two Values in Two Rows
How to Escape Ampersand in Toad
How to Perform a Bitwise Group Function
SQL Update Query Syntax with Inner Join
Resources Exceeded During Query Execution
Is Null VS = Null in Where Clause + SQL Server
Postgresql: Top N Entries Per Item in Same Table
Is There a Coalesce-Like Function in Excel
How to Concatenate Text in a Query in SQL Server
Add Row Number to This T-SQL Query
Sql: Search for a String in Every Varchar Column in a Database