Professional Web Applications Themes

selecting from two tables - MySQL

Hi I have one table called 'foobar_items' ID desc ________ ________________ foo1 very good foo foo2 average foo foo3 bad foo bar1 great bar bar2 average bar And another table called 'foobar_searches' Type Keyword Color ________ ___________________ ________________ foo foo foos Blue bar bar bars Red I need to search for a match in either table.. How do I write the syntax? For example.... if I do: SELECT * FROM foobar_items, foobar_searches WHERE foobar_items.foo LIKE ('%blue%') OR foobar_searches LIKE ('%blue'%) I get cross referenced results(10 rows) instead of 2 rows What is the syntax to only get 2 rows? Thanks...

  1. #1

    Default selecting from two tables

    Hi I have one table called 'foobar_items'

    ID desc
    ________ ________________

    foo1 very good foo
    foo2 average foo
    foo3 bad foo
    bar1 great bar
    bar2 average bar




    And another table called 'foobar_searches'

    Type Keyword Color
    ________ ___________________ ________________

    foo foo foos Blue
    bar bar bars Red

    I need to search for a match in either table.. How do I write the
    syntax? For example....

    if I do:
    SELECT * FROM foobar_items, foobar_searches WHERE foobar_items.foo LIKE
    ('%blue%') OR foobar_searches LIKE ('%blue'%)

    I get cross referenced results(10 rows) instead of 2 rows

    What is the syntax to only get 2 rows?

    Thanks

    ron1972 Guest

  2. #2

    Default Re: selecting from two tables

    ron1972 wrote:
    > Hi I have one table called 'foobar_items'
    >
    > ID desc
    > ________ ________________
    >
    > foo1 very good foo
    > foo2 average foo
    > foo3 bad foo
    > bar1 great bar
    > bar2 average bar
    >
    >
    >
    >
    > And another table called 'foobar_searches'
    >
    > Type Keyword Color
    > ________ ___________________ ________________
    >
    > foo foo foos Blue
    > bar bar bars Red
    >
    > I need to search for a match in either table.. How do I write the
    > syntax? For example....
    >
    > if I do:
    > SELECT * FROM foobar_items, foobar_searches WHERE foobar_items.foo LIKE
    > ('%blue%') OR foobar_searches LIKE ('%blue'%)
    >
    > I get cross referenced results(10 rows) instead of 2 rows
    >
    > What is the syntax to only get 2 rows?
    >
    > Thanks
    >
    Ron,

    You need to also define the relationship between the two tables, i.e.

    WHERE foobar_items.ID = foobar_searches.Type AND (...)

    BTW, I'm not exactly sure what you're trying to accomplish. You don't
    have a column "foo" in either table, and you didn't specify a column for
    foobar_searches. Assuming you're trying to list all the information for
    an item that is blue, you'd have something like:

    SELECT * FROM foobar_items, foobar_searches
    WHERE foobar_items.ID = foobar_searches.Type
    AND foobar_searches.Color LIKE %Blue%

    Also, since your column names are unique, this can be shortened to:

    SELECT * FROM foobar_items, foobar_searches
    WHERE ID = Type
    AND Color LIKE %Blue%


    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    [email]jstucklexattglobal.net[/email]
    ==================
    Jerry Stuckle Guest

Similar Threads

  1. SELECTING ROWS
    By MacroDuck in forum Coldfusion Database Access
    Replies: 2
    Last Post: April 20th, 06:58 PM
  2. SQL: Selecting everything BUT
    By darrel in forum Dreamweaver AppDev
    Replies: 2
    Last Post: March 28th, 07:42 PM
  3. selecting different css
    By danilocelic *TMM* in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: February 16th, 10:06 PM
  4. Selecting
    By Wilfried in forum ASP.NET Security
    Replies: 6
    Last Post: October 27th, 06:27 AM
  5. Selecting 2 or more objects! (Please help)
    By Barryk webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 2
    Last Post: September 27th, 08:59 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139