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,472
There are 1983 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

JOIN two queries using the 1st query results?

Thread title: JOIN two queries using the 1st query results?
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
06-04-2012, 01:37 PM
#5
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

As a general rule it is best to use one query opposed to two because each query has overhead for execution. Even if one query takes longer than either two it will still run faster than the two combined. It's also better practice, you want your database to do as much of the data processing as possible opposed to having PHP play a part in it. Also, don't use SELECT *, it takes longer to run and leaves ambiguity in your code. Do something like

Code:
SELECT topics.field1, users.field2 [ect]
FROM `forum topics` topics
LEFT JOIN users ON users.id=topics.author
WHERE slug=[$slug]
I wouldn't select from two tables here since you are conditionally joining a second table to a first, that is what JOIN is for.

Thanked by:
Dan (06-04-2012)
     


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

  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