Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Location
    Edinburgh, Scotland
    Posts
    2

    Unanswered: Simple SQL join?

    Hi

    I'm quite new to SQL, but know some basics. I'm having a problem with a MySQL query. I want to select from two tables, but view the results based on more than two conditions. I have two tables:

    site (name, mapref, etc..)
    site_type (name, type1, type2)

    These are pre/historic sites, so I'd like to select all the types of 'Castle', for example, (which may be in either type1 or type2) but display information from both tables - name, mapref, type1, type2.

    I've tried:

    SELECT site.name, mapref, type1, type2
    FROM site, site_type
    WHERE site.name = site_type.name AND type1 = "Castle";

    That works fine, but I can't do anything like -
    AND type1 = "Castle" OR type2 = "Castle";
    ..that throws back some strange results which I'm sure has to do with the type of join. I've no idea about inner joins ets - is that required here or is there a way to do it with a condition.

    Many thanks

    Tony

  2. #2
    Join Date
    Feb 2003
    Location
    Edinburgh, Scotland
    Posts
    2
    Would you believe it

    I'd searched the forum for this, but missed a reply given to a similar post a few days ago by frankn - the problem is solved by using brackets to change the operator precedence. In my case the solution is:

    SELECT site.name, mapref, type1, type2
    FROM site, site_type
    WHERE site.name = site_type.name AND (type1 = "Castle" OR type2 = "Castle");

    Tony

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •