MyBB Community Forums

Full Version: SQL: Multiple records from one table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Getting Multiple records from single table is good if we compare to multiple queries. In my plugin, i've seen i am using upto 4-5 queries. 2 queries from a single table and 2 queries from another table.
i want to join queries in single query.
Queries:

FIRST

//fetch referrer from, need to add this query because this action can be done by mods/admin so can't use $mybb->user['uid']
$query = $db->simple_select("users", "postnum,referrer,referrerstatus", "`uid` = '".$uid."'");

// getting data
$results = $db->fetch_array($query);



SECOND
// getting referrer information
$query = $db->simple_select("users", "referrals", "`uid` = '".$results['referrer']."'");

$results = $db->fetch_array($query);

if both queries execute in single statement then it will very useful...
In the same function, i've two another queries like this for second table
Use LEFT JOIN.
Check this out: http://www.dofactory.com/sql/left-outer-join