7 Replies - 622 Views - Last Post: 26 May 2011 - 02:17 PM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

INNER JOIN

Posted 26 May 2011 - 10:29 AM

Quote

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/web04/b2008/moo.battlesccom/view_topic.php on line 100


$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' INNER JOIN * FROM members ON members.id";

Is This A Good Question/Topic? 0
  • +

Replies To: INNER JOIN

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,617
  • Joined: 08-June 10

Re: INNER JOIN

Posted 26 May 2011 - 10:30 AM

the join syntax is wrong, it’s JOIN table ON expression or JOIN table USING(common_column).

there are nice flow charts for the syntax on the SQLite site.

This post has been edited by Dormilich: 26 May 2011 - 10:35 AM

Was This Post Helpful? 1
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2836
  • View blog
  • Posts: 9,741
  • Joined: 08-August 08

Re: INNER JOIN

Posted 26 May 2011 - 10:33 AM

I think I'd use something like this:
$sql2="SELECT * FROM $tbl_name2, members WHERE $tbl_name2.question_id='$id' AND members.id = '$id;";


because it's easier to read.
Was This Post Helpful? 2
  • +
  • -

#4 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: INNER JOIN

Posted 26 May 2011 - 10:48 AM

That looks wrong, I got a table name forum_question that i am trying to INNER JOIN with a table name members
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,617
  • Joined: 08-June 10

Re: INNER JOIN

Posted 26 May 2011 - 10:56 AM

on what condition?
Was This Post Helpful? 0
  • +
  • -

#6 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: INNER JOIN

Posted 26 May 2011 - 02:02 PM

id with id, is there a way to select * from members and * from forum_question?
Was This Post Helpful? 0
  • +
  • -

#7 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: INNER JOIN

Posted 26 May 2011 - 02:11 PM

So your wanting to select all from two tables based on id correct??

$query = "SELECT t1.*, t2.* 
			FROM table1 AS t1
				INNER JOIN tabnl2 AS t2 
				ON t1.id = t2.id
			WHERE t1.id = $id";



That's actually a working query from a CMS I wrote minus the fact i very rarely use * ... i normally name all rows.

What CT wrote is fairly easy to read if you just looking for a plain select all statement however.

This post has been edited by RPGonzo: 26 May 2011 - 02:15 PM

Was This Post Helpful? 1
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,617
  • Joined: 08-June 10

Re: INNER JOIN

Posted 26 May 2011 - 02:17 PM

an alternate writing:
$query = "SELECT t1.*, t2.* 
		FROM table1 AS t1
		INNER JOIN tabnl2 AS t2 USING(id)
		WHERE t1.id = $id";


Was This Post Helpful? 2
  • +
  • -

Page 1 of 1