Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   Syntax for Select Statement (http://www.go4expert.com/forums/syntax-select-statement-t24158/)

newphpcoder 13Dec2010 08:32

Syntax for Select Statement
 
Good day!

I want to know if what is the correct sysntax for Selecting multiple data in one column.

I have a table trace and i have column name and id
my list name are: name1, name1total, name2,name2total,name3,name4, and name5, but i wamnt to select only is the name 1,name3,name4, and name5
I have a table trans and it has id.
I try this code:
Code:

SELECT t.name FROM trace t, trans c WHERE t.name = 'name1' || 'name 3' || 'name4' || 'name5' AND t.id=c.id;
In that code all the name was selected eventhough I did not select the name1total,name2,name2total.
Thank you

venami 13Dec2010 18:03

Re: Syntax for Select Statement
 
Your SQL should look like this:

Code:

SELECT t.name FROM trace t, trans c WHERE (t.name = 'name1' or t.name =  'name 3' or t.name = 'name4' or t.name = 'name5') AND t.id=c.id;
or like this:

Code:

SELECT t.name FROM trace t, trans c WHERE t.name in ('name1', 'name 3', 'name4', 'name5') AND t.id=c.id;


All times are GMT +5.5. The time now is 05:22.