If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How can I

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-06-11, 10:48
keespost keespost is offline
Registered User
 
Join Date: Sep 2011
Posts: 1
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 10:51. Reason: Want to edit the title, but it is not possible?
Reply With Quote
  #2 (permalink)  
Old 09-06-11, 13:38
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 09-07-11, 02:41
bchanan bchanan is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On