join problem in mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kumarboston
    New Member
    • Sep 2007
    • 55

    join problem in mysql

    Hello All,

    I have 2 tables
    a) main: has 2 columns- id and name.
    b) alias: has 2 column -id and alternate name.
    both the tables are joined through id, now what I am trying to do is if user enters either the name or the alternate name , it should return me the id and the name.

    When I tried to use 'OR' as the operator, it returned me all the entries of the database.

    Kindly anyone suggest the possible solutions.

    Thanks
    Kumar
  • psicopunx
    New Member
    • Oct 2007
    • 1

    #2
    Dear Kumar,

    Please, post your query.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by kumarboston
      Hello All,

      I have 2 tables
      a) main: has 2 columns- id and name.
      b) alias: has 2 column -id and alternate name.
      both the tables are joined through id, now what I am trying to do is if user enters either the name or the alternate name , it should return me the id and the name.

      When I tried to use 'OR' as the operator, it returned me all the entries of the database.

      Kindly anyone suggest the possible solutions.

      Thanks
      Kumar
      Did you try
      [CODE=mysql]select n.id, n.name from name n join alias a on n.id = a.id
      where n.name = "givenName" or a.alternateName = "givenName"[/CODE]

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Or even:
        [code=mysql]
        SELECT n.ID, n.Name
        FROM tblName as n
        INNER JOIN tblAlt as a
        ON n.ID = a.ID
        WHERE 'searchTerm' IN (n.Name, a.Name)
        [/code]

        Comment

        Working...