Results 1 to 3 of 3

Thread: How can I

  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Unanswered: How can I

    Hi,

    I've got the following query:

    Code:
    SELECT b.*, a.* FROM books b LEFT JOIN authors a ON b.autor_id = b.id
    Is it possible to get all columns from the table authors with a prefix? So I can see in my php code from what table the field is comming?

    I want something like this:

    Code:
    SELECT b.*, a.* as author+nameOfTheColumn FROM books b LEFT JOIN authors a ON b.autor_id = b.id
    ---
    Forgot to change the title, but now I cannot change it anymore?
    Last edited by keespost; 09-06-11 at 11:51. Reason: Want to edit the title, but it is not possible?

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    I am not too sure what you are asking for here? If you do something like:

    Code:
    SELECT b.*, a.author FROM books b LEFT JOIN authors a ON b.autor_id = b.id
    Then in PHP

    Code:
    while($row = mysql_fetch_assoc($res)) {
      $row['author'] contains the information from the author field
    }
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Dec 2009
    Posts
    27

    you can

    More east way to select specific fields from both tables, and use alias
    (assuming you are not altering the tables structure often)

    example:
    create table kuku1(f1 int, f2 int);
    create table kuku2(f1 int, f2 int);

    select kuku1.f1 as kuku1_f1,
    kuku1.f2 as kuku1_f2,
    kuku2.f1 as kuku2_f1,
    kuku2.f2 as kuku2_f2
    from kuku1,
    kuku2
    where kuku1.f1 = kuku2.f1

Posting Permissions

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