Syntax for Select Statement

Discussion in 'MySQL' started by newphpcoder, Dec 13, 2010.

  1. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    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
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    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;
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice