How to perform a double consultation in the Standard?

Asked

Viewed 544 times

1

I have a query in SQL Ansi:

select * from payments as P, receipts as R 
where P.created_at < CURRENT_DATE AND P.updated_at < CURRENT_DATE AND R.created_at < CURRENT_DATE AND R.updated_at < CURRENT_DATE

Precious to perform the same query in the Standard:

public function relatorioBI(){

        //1 A pagar

        $query = $this->newQuery();

        $query->where('created_at','1');

        return $this->doQuery($query, $take, $paginate);
    }

I need to perform the query in both tables, and test the conditional value!

  • You can use DB::select!

  • Have some example to demonstrate???

  • https://answall.com/search?q=DB%3A%3Aselect a few examples

1 answer

1


Use the \DB::select that the simple way to carry out consultations in this way:

Example:

$sql = ' select * from payments as P, receipts as R ';
$sql .= ' where P.created_at < CURRENT_DATE AND P.updated_at < CURRENT_DATE ';
$sql .= ' AND R.created_at < CURRENT_DATE AND R.updated_at < CURRENT_DATE';

$users = \DB::select($sql);  

Observing: in the site already exists several examples see link.

If you need to use parameters follow an example from the documentation of :

\DB::select('select * from users where active = ?', [1]);

that is to say, one array according to the sequence and amount of parameter (?).

Reference: Running Raw SQL Queries

Browser other questions tagged

You are not signed in. Login or sign up in order to post.