Q:

Execute a SQL query/statement conditionally based on table data

First, take a look at this table, basically I need to UPDATE (+1) a ticket WHERE the Username equals to Jondoe AND Money is greater than 200.

Now, I know I can execute 3 queries, first to check if the actual user has Jondoe as Username, then check if he has enough Money and if these results are true, then UPDATE (+1)  a ticket finally.
I'm learning SQL and i'm working over a mssql database, what's the proper way to do such a conditional query/update? Can I avoid using that many queries?
I'm also working with laravel framework, I don't know if it comes with any "tool" to accomplish what I want.
Thanks in advance

A:

Laravel has the fluent query builder which you can use (more or less) like below:
$affectedRows = DB::table('TableName')
    ->where("Username", "Jondoe")
    ->where("Money",">",200)
    ->increment("Tickets");

You can also use $affectedRows to check if there were any updates made.   
Edit:
If you have a user model (e.g. named User) then you can use the same syntax but with Eloquent.
Example:
User::where("Username", "Jondoe")
    ->where("Money",">",200)
    ->increment("Tickets");

Eloquent is Laravel's ORM (Object-Relational model) which provides a mapping between relational databases and PHP objects (i.e. the model part of the MVC framework). It's not a query builder itself but it does use fluent in the background to build queries. 
Reference https://laravel.com/docs/5.0/queries

