Select Statement
Select data from Database table.
$result =
$db::select('posts.ID', 'posts.post_title')
->distinct()
->from('posts posts')
->where('posts.post_status', '=', 'publish')
->orderBy('post_title', 'DESC')
->limit(10)->offset(2)
->get();
$data =
DB::select('posts.ID', 'posts.post_title')
->distinct()
->from('posts posts')
->where(function($query) {
$query->where('posts.post_status', '=', 'publish')
->andWhere('posts.post_type', '=', 'page');
})
->orderBy('post_title', 'DESC')
->get();
Join tables
$db::select('users.display_name name')
->count('posts.ID', 'posts')
->from('users users')
->join('posts posts')
->where('posts.post_status', '=', 'publish')
->andWhere('posts.post_type', '=', 'post')
->get();
$db::select('posts.post_title')
->from('posts posts')
->innerJoin('term_relationships term_rel', 'posts.ID', 'term_rel.object_id')
->where('posts.post_status', '=', 'publish')
->get();
Get only raw SQL without database query execution.
$sql=
DB::select('posts.ID', 'posts.post_title')
->from('posts posts')
->where('posts.post_status', '=', 'publish')
->orderBy('post_title', 'DESC')
->getSql();