Ihidan
Ihidan

Reputation: 419

Mysql select from a array

To select something from the data base we could use:

SELECT * FROM tableName where name="Ed"

But what if I need to select something from a given array, eg:

SELECT * FROM ("Bob","Sam","Ed") where name="Ed"

Is it possible?

Upvotes: 2

Views: 2076

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133370

You can try with

    SELECT * FROM ( 
        select "Bob" as name
        from dual
        union
        select "Sam" as name
        from dual
        union 
        select "Ed"as name
        from dual ) as t
    where t.name="Ed";

Upvotes: 0

Alex
Alex

Reputation: 17289

Yes it is possible:

http://sqlfiddle.com/#!9/9eecb7d/64737

SELECT t.* FROM 
(SELECT "Bob" name UNION SELECT "Sam" UNION SELECT "Ed") t
WHERE t.name="Ed"

But it has almost no sense. Because if you set all data as constant static values you can just:

SELECT "Ed"

there is no reason even to call mysql :-)

Upvotes: 1

Related Questions