Imagine that I have a column like this:
Var: 1, 1, , 3, 2
-
Name: Ben, John, Josh, Bill
How can I select Entries with the same VAR
column Value? Like, if I want entries with value 1
in the VAR
column, it will give me Ben
and Josh
.
Imagine that I have a column like this:
Var: 1, 1, , 3, 2
-
Name: Ben, John, Josh, Bill
How can I select Entries with the same VAR
column Value? Like, if I want entries with value 1
in the VAR
column, it will give me Ben
and Josh
.
Try
SELECT name
FROM table1
WHERE var IN (SELECT MIN(var)
FROM table1
GROUP BY var
HAVING COUNT(*) > 1)
Here is SQLFiddle demo.
This will give you records having multiple records of the same VAR
.
SELECT a.*
FROM TableName a
WHERE EXISTS
(
SELECT 1
FROM TableName b
WHERE a.Var = b.Var
GROUP BY Var
HAVING COUNT(*) > 1
)
Another way to solve this is by using JOIN
,
SELECT a.*
FROM TableName a
INNER JOIN
(
SELECT Var
FROM TableName b
GROUP BY Var
HAVING COUNT(*) > 1
) b ON a.Var = b.Var
But adds a little confusion when you add this line: "..if I want entries with value 1 in the VAR column, it will give me: Ben and Josh" -- Do you want to specify VAR
or not? Like this demo <<
this question is confusing, does a select not work?
select name from theTable
where var = 1