2

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?

1
  • 2
    you can fake up a fable, select * from (select 'bob' union select 'sam' union ....) as foo Commented Jun 17, 2016 at 18:37

2 Answers 2

1

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 :-)

Sign up to request clarification or add additional context in comments.

3 Comments

In OP's case, no it doesn't make much sense. However it would if some MySQL functions needs to be called. I'd really appreciate if I can do this: SELECT FROM_UNIXTIME(FooTable.Time) FROM (SELECT ('1428384605','1429657398','1429686889') as Time) AS FooTable
@LionetChen but do you have WHERE time='1429686889' at the end? ;-)
I don't have that filter :P hence I said "in OP's case". I know I could've achieved the conversion with Excel but I was in the SQL query editor and just too lazy to open up Excel to type in those formulas LOL
0

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";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.