Results 1 to 6 of 6

Thread: query two tables

  1. #1
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default query two tables

    hi i have product A and B

    A have
    Aid
    price
    date
    isbn

    B have
    Aid
    price
    date
    album

    i want to select them in one place i want just id,price and date
    how can i query this!!??? thank you

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Does this help you?
    Code:
    $query ="SELECT table1.field1, table2.field2 FROM table1, table2 WHERE table1.field1=table2.field2";
    Red: Field in table1.
    Navy: Field in table2.
    LightGray: Table1.
    DarkGray: Table2.
    You can get a bit more info on that here: http://www.w3schools.com/sql/sql_join.asp
    I hope this helps,
    Nile
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I'm sorry dude but table 1 and table 2 it doesn't have any relationship

    ok table 1 is Book product and table 2 is cd product right and i want to view it at once in same list i build and the information that 2 table have the is price and title for example
    so if i list it all when i click it it will go to product's page so that's mean book_id and cd_id is not the same right? do i miss anyhting

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Sorry, I didn't understand that. Could you please rephrase it?
    Jeremy | jfein.net

  5. #5
    Join Date
    Jul 2007
    Posts
    59
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    i have
    table of product A
    - Aid
    - Price
    - Adetail

    table of product B
    - Bid
    - Price
    - Bdetail

    2 of these table r not have any relationship
    how can i view this 2 tables in one query
    how can i do that???

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    SELECT f1, f2 FROM t1 WHERE f1='foo' UNION(SELECT f3, f4 FROM t2 WHERE f3='foo')
    http://dev.mysql.com/doc/refman/5.0/en/union.html

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
  •