22, March 2010

join question - field names - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: join question - field names
« previous next »
Pages: [1] Print

Author Topic: join question - field names  (Read 1188 times)
OMG!I am geek
**
Posts: 53
406 credits
Members referred : 0


« on: Jan 25, 2008, 07:38:28 am »

when joining 2 tables and in the tables they both have a field that has the same name, is there a way to display both when doing the call?

when doing something like
Code:
SELECT table1.time_created, table2.time_created FROM table1 left join table2

it shows only one time_created
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jan 25, 2008, 08:16:49 am »

SELECT table1.time_created AS time1, table2.time_created AS time2 FROM table1 left join table2


Last blog : A new Wordpress theme for our blog
OMG!I am geek
**
Posts: 53
406 credits
Members referred : 0


« Reply #2 on: Jan 25, 2008, 06:44:11 pm »

gah...i should have known that...i know i have used that AS command before hehe
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5660
45593 credits
Members referred : 3



« Reply #3 on: Jan 26, 2008, 11:11:20 am »

Hmmm, I believe the first implementation will work too, but you will have to call them with their numbers not names ( eg. $rec[0] . $rec[1] )

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jan 26, 2008, 11:49:06 am »

Hmmm, I believe the first implementation will work too, but you will have to call them with their numbers not names ( eg. $rec[0] . $rec[1] )

yes sure but it works so good working with acc. arrays or objets Wink


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5660
45593 credits
Members referred : 3



« Reply #5 on: Jan 26, 2008, 12:23:33 pm »

I agree, it's the worst way to do this, I just wanted to point out that it can be done this way too Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6690
34708 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Jan 26, 2008, 12:28:18 pm »

I have very often dynamic field names like:

$sql = sprintf("SELECT name%s FROM table1", $lang);

in this case it's the best way to use some new "name" in your statement


Last blog : A new Wordpress theme for our blog
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7548
Tags : mysql left join Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  Databases  >  MySQL
Topic: join question - field names
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Mar 22, 2010, 09:59:16 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!





Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2010 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.