Log in

View Full Version : Syntx for Select Statement



rhodarose
12-13-2010, 01:54 AM
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, 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:



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

heavensgate15
12-13-2010, 11:09 AM
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;


If it doesn't work, try to group all the ORs with the use of parenthesis, because I think, the AND operator is executed first before the OR, so when t.id = c.id is TRUE, then it will not execute the ORs statement.. I'm not sure though.. It's just a tip....



or you can do it this way:

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


Note: I haven't tried this code... I'm just experimenting... But I'm not joking around...