Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 739 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Need help with multiple SQL tables (JOIN)

Thread title: Need help with multiple SQL tables (JOIN)
Reply    
    Thread tools Search this thread Display Modes  
10-01-2009, 12:13 PM
#1
.Cyanide is offline .Cyanide
Status: Senior Member
Join date: Mar 2006
Location: Stockholm,Sweden
Expertise: Web Design, Coding
Software: Phoshop CS3
 
Posts: 757
iTrader: 4 / 100%
 

.Cyanide is an unknown quantity at this point

Send a message via MSN to .Cyanide

  Old  Need help with multiple SQL tables (JOIN)

Hey,

I have this code:

PHP Code:
$sql "SELECT * FROM debate, sports, culture, economy WHERE author LIKE '%Eva Svensson%'"
As you can see, I'm trying to search through all the four tables "debate, sports, culture, economy" for posts by the author Eva Svensson, and when found, I want to print the whole post (headline, text, author, date).

Now, I know my current SQL query does not work, so I've been reading up on the JOIN command, which I can't seem to understand. So my question is: Could anyone who knows how to JOIN multiple tables help me write the SQL query I need?

Thanks alot,
Jakob

Reply With Quote
10-01-2009, 12:19 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

I may have missed the point, but it looks like you might be wanting to use a UNION rather than a JOIN since you just want to query multiple tables rather than join anything together.

See http://dev.mysql.com/doc/refman/5.4/en/union.html

Aside: whether you know it or not, by separating the tables by commas as you have, you're already doing an INNER JOIN on those tables.

Reply With Quote
10-01-2009, 12:34 PM
#3
.Cyanide is offline .Cyanide
Status: Senior Member
Join date: Mar 2006
Location: Stockholm,Sweden
Expertise: Web Design, Coding
Software: Phoshop CS3
 
Posts: 757
iTrader: 4 / 100%
 

.Cyanide is an unknown quantity at this point

Send a message via MSN to .Cyanide

  Old

Originally Posted by Salathe View Post
I may have missed the point, but it looks like you might be wanting to use a UNION rather than a JOIN since you just want to query multiple tables rather than join anything together.

See http://dev.mysql.com/doc/refman/5.4/en/union.html

Aside: whether you know it or not, by separating the tables by commas as you have, you're already doing an INNER JOIN on those tables.
The URL you provided didn't work =/

Aside: I am? Because when I try using that query I get an error message saying:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\FTPROOT\KTD\sh09hf1763\www\webbapplikationer09\ lab4\lab.php on line 26

EDIT: I used UNION, which was ALOT easier to understand, and now it works perfectly

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed