lopata
lopata

Reputation: 1365

MYSQL: get data that have similar column

I have this in my database:

id | column1
1 | ab
2 | cd
3 | cd
4 | ef
5 | cd
6 | ab

And I would like to get either ids :(1,6) or (2,3,5) or (4) but it has to have the same column1 name

I don't have a specific column1 name to search.

I want something that does the same thing as:

row=SELECT column1 FROM table LIMIT 1
row2=SELECT id FROM table WHERE column1=row[0].column1

but in one query, is that possible?

Upvotes: 0

Views: 30

Answers (2)

user3585329
user3585329

Reputation:

SELECT id FROM table INNER JOIN table AS table2 ON table.column1=table2.column1

is probably the nearest you are going to get then you just use a WHERE clause such as WHERE table.column1='ab'

Upvotes: 0

JShell
JShell

Reputation: 624

You can nest SQL queries

row= SELECT id FROM table WHERE column1=(SELECT column1 FROM table LIMIT 1)

Upvotes: 1

Related Questions