| |
|
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.
|
 |

10-21-04, 07:05
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 33
|
|
|
|
Quote:
|
Originally Posted by r937
please allow me to suggest that you (1) learn JOIN syntax, and (2) always use indentation and line breaks when writing SQL
Code:
SELECT jos_content.title
, jos_content.introtext
, jos_content.created_by
, jos_content.sectionid
, jos_content.id
, jos_users.name
, jos_sections.title AS 'sectitle'
, jos_sections.id AS 'secid'
FROM jos_content
INNER
JOIN jos_users
ON jos_users.id = jos_content.created_by
INNER
JOIN jos_sections
ON jos_sections.id = jos_content.sectionid

|
Thanks for the tip. You're probably right proper formatting; isn't inner join the same thing as join though?
SQL INNER JOIN Keyword
|
|

08-26-09, 17:18
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 33
|
|
|
querying, alias is returning NULL
Code:
$result = mysql_query("SELECT jos_content.title, jos_content.introtext, jos_content.created_by, jos_content.sectionid, jos_content.id, jos_users.name, jos_sections.title AS 'jos_sections.sectitle', jos_sections.id AS 'jos_sections.secid' FROM jos_content, jos_users, jos_sections WHERE (jos_content.created_by = jos_users.id AND jos_content.sectionid = jos_sections.id)");
$t = 0;
while($row = mysql_fetch_array($result))
{
$entry[$t][0] = $row['id'];
$entry[$t][1] = $row['title'];
$entry[$t][2] = $row['name'];
$entry[$t][3] = $row['sectionid'];
$entry[$t][4] = $row['introtext'];
$entry[$t][5] = $row['sectitle'];
$t++;
}
for some reason $row['sectitle'] is returning null. Any ideas as to what would cause this? It's only that one attribute.
|
|

08-26-09, 17:21
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 33
|
|
|
|
sorry, I cleaned it up a little bit :P
Code:
$query = "SELECT jos_content.title, jos_content.introtext, jos_content.created_by, ".
"jos_content.sectionid, jos_content.id, jos_users.name, jos_sections.title AS 'jos_sections.sectitle', ".
"jos_sections.id AS 'jos_sections.secid' FROM jos_content, jos_users, jos_sections ".
"WHERE (jos_content.created_by = jos_users.id AND jos_content.sectionid = jos_sections.id)";
$result = mysql_query($query);
$t = 0;
while($row = mysql_fetch_array($result))
{
$entry[$t][0] = $row['id'];
$entry[$t][1] = $row['title'];
$entry[$t][2] = $row['name'];
$entry[$t][3] = $row['sectionid'];
$entry[$t][4] = $row['introtext'];
$entry[$t][5] = $row['sectitle'];
$t++;
}
still no luck though
|
|

08-26-09, 17:26
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 33
|
|
bangs head against mysql manual. lol, ok I was using the alias incorrectly.
Code:
$query = "SELECT jos_content.title, jos_content.introtext, jos_content.created_by, ".
"jos_content.sectionid, jos_content.id, jos_users.name, jos_sections.title AS 'sectitle', ".
"jos_sections.id AS 'secid' FROM jos_content, jos_users, jos_sections ".
"WHERE (jos_content.created_by = jos_users.id AND jos_content.sectionid = jos_sections.id)";
|
|

08-26-09, 20:16
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
|
|
please allow me to suggest that you (1) learn JOIN syntax, and (2) always use indentation and line breaks when writing SQL
Code:
SELECT jos_content.title
, jos_content.introtext
, jos_content.created_by
, jos_content.sectionid
, jos_content.id
, jos_users.name
, jos_sections.title AS 'sectitle'
, jos_sections.id AS 'secid'
FROM jos_content
INNER
JOIN jos_users
ON jos_users.id = jos_content.created_by
INNER
JOIN jos_sections
ON jos_sections.id = jos_content.sectionid

|
|

08-27-09, 10:20
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 33
|
|
Quote:
|
Originally Posted by r937
please allow me to suggest that you (1) learn JOIN syntax, and (2) always use indentation and line breaks when writing SQL
Code:
SELECT jos_content.title
, jos_content.introtext
, jos_content.created_by
, jos_content.sectionid
, jos_content.id
, jos_users.name
, jos_sections.title AS 'sectitle'
, jos_sections.id AS 'secid'
FROM jos_content
INNER
JOIN jos_users
ON jos_users.id = jos_content.created_by
INNER
JOIN jos_sections
ON jos_sections.id = jos_content.sectionid

|
Thanks for the tip. My code can definitely use some formatting, I was under the assumption that inner join and join where the same though though.
SQL INNER JOIN Keyword
|
|

08-27-09, 13:07
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
|
|
Quote:
|
Originally Posted by Schweppesale
I was under the assumption that inner join and join where the same though though. 
|
yes, sort of
first, JOIN equates to INNER JOIN, at least in mysql, but it's better always to write INNER JOIN and not just JOIN (in earlier versions JOIN equated to CROSS JOIN)
second, you had FROM jos_content, jos_users, jos_sections WHERE ... which technically is an inner join but this syntax is old style and should be rewritten with JOIN syntax
besides, if you wanted to change one of those joins to an outer join, you'd have to rewrite it anyway
|
|

08-27-09, 13:13
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 2,407
|
|
Quote:
|
Originally Posted by r937
JOIN equates to INNER JOIN
|
That's what the standard requires.
Quote:
|
Originally Posted by ANSI SQL
If a <qualified join> or <natural join> is specified and a <join type> is not specified, then INNER is implicit.
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|