Laravel's database query builder provides a convenient, fluent interface to creating and running database queries.
- It uses PDO parameter binding to protect your application against SQL injection. There is no need to clean strings passed as bindings.


To perform a basic "inner join", you may use the join() method on a query builder instance.
The first argument is the name of the table you need to join to; the remaining arguments specify the relation of the columns for the join.
- You can join to multiple tables in a single query:
$users = DB::table('users')
 ->join('contacts', '', '=', 'contacts.user_id')
 ->join('orders', '', '=', 'orders.user_id')
 ->select('users.*', '', 'orders.price')
- To perform a "left join" query, use the leftJoin() method, in the same way as the join() method.
$users = DB::table('users')
 ->leftJoin('posts', '', '=', 'posts.user_id')


To "union" two queries together, create an initial query and use the union() method to union it with a second query.
$first = DB::table('users')->whereNull('first_name');

$users = DB::table('users')->whereNull('last_name')

- Documentation: Laravel - Database: Query Builder

Daily Test with Code Example

Which HTML5 tag is indicated to be used as container for menu with navigation links in Web site?
<section> <nav> <article>
 <li><a href="" title="CSS Course">CSS Course</a></li>
 <li><a href="" title="Flash Games">Flash Games</a></li>
Which CSS property shifts an item horizontally to the left or right of where it was?
text-align clear float
.some_class {
  width: 30%;
  float: left;
Click on the Math object method which returns x, rounded downwards to the nearest integer.
Math.ceil(x) Math.abs(x) Math.floor(x)
var num = 12.34567;
num = Math.floor(num);
alert(num);       // 12
Indicate the PHP function which returns the number of characters in string.
mb_strlen() count() stristr()
$str = "string with utf-8 chars åèö";
$nrchr = mb_strlen($str);
echo $nrchr;        // 30
MySQL Database, Query Builder: Join and Union

Last accessed pages

  1. Ajax-PHP Rating Stars Script (12967)
  2. Read Excel file data in PHP - PhpExcelReader (56584)
  3. Disable button and Enable it after specified time (6135)
  4. Send Email with Nodemailer (520)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (41515)

Popular pages this month

  1. Read Excel file data in PHP - PhpExcelReader (321)
  2. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (265)
  3. Register and show online users and visitors (253)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (244)
  5. Insert, Select and Update NULL value in MySQL (156)