SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    None
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm a bit confused here... I need to select everything from multiple tables, but am not sure why my query won't execute... I would use Unions, but MySQL don't support them...

    I have 3 tables in one database.

    table_1
    table_2
    table_3

    Query: select * from table_1, table_2, table_3 where name = "someName";

    The data in those tables is different.

    May be I need to use joins, to join 3 tables? Can't figure out what to do.

  2. #2
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the error you get when you run the query from the command line or phpMyAdmin?

    I suspect it might be.. name clause is ambiguous. Try:

    Select * from table_1,table_2,table_3 where table_1.name='somename'

    specifying what table name should come from
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  3. #3
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    None
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I get "name clause is ambiguous" error message.

    I can't use "where table_1.name" because:

    1. the data it all 3 tables is different
    2. the "name" comes from an input box:

    <input type="text" name="some_name">

    So I need to search all 3 tables for "$some_name"...

    select * from table_1,table_2,table_3 where name = \"$some_name\"

    Any ideas?
    Last edited by Pweb; Apr 25, 2001 at 10:33.

  4. #4
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure no problem..

    select * from table_1,table_2,table_3
    where table_1.name = "$some_name"
    or table_2.name = "$some_name"
    or table_3.name = "$some_name"

    btw, that is a standard join except you're using ,commas, instead of the JOIN structure
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content


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
  •