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 tag renders as emphasized text, displaying the text oblique?
<strong> <pre> <em>
<p>Web development courses: <em></em></p>
Which CSS property defines the space between the element border and its content?
margin padding position
h3 {
  padding: 2px 0.2em;
Click on the method which returns the first element that matches a specified group of selectors.
getElementsByName() querySelector() querySelectorAll()
// gets first Div with class="cls", and shows its content
var elm = document.querySelector("div.cls");
Indicate the PHP variable that contains data from a form sent with method="post".
if(isset($_POST["field"])) {
  echo $_POST["field"];
Laravel - MySQL Database, Query Builder: Join and Union

Last accessed pages

  1. JavaScript strip_tags and stripslashes (2626)
  2. Add and Remove HTML elements and Content with jQuery (20571)
  3. We Are Friends (108)
  4. Puzzle Games (11148)
  5. Creating objects in ActionScript (6344)

Popular pages this month

  1. Qwop (6303)
  2. Drag Racer V3 (4297)
  3. Bubbles3 (1798)
  4. List with All the Games (1481)
  5. Butterfly Kyodai (1413)