This question already has answers here:
How to select specific columns in laravel eloquent
(23 answers)
Closed 6 months ago.
This code fetches all the data in the table in the database, but I want to set a maximum limit, for example, it fetches only 4 columns from the table so that it does not load all the columns in the table
'productes' => productModel::orderBy('id', 'DESC')->get()
'productes' => productModel::orderBy('id', 'DESC')->limit(20)->get(['id',...])
Try this. But I'm highly recommended you read laravel documentation
limit is the count of rows that will be fetched from DB and
get will fetch columns that you passed in the array
Related
This question already has answers here:
Difference between Laravel DB::insert() and DB::table()->insert()
(3 answers)
Closed 1 year ago.
what is the differences of following two:
DB::update(
'update users set votes = 0 where votes < 0'
);
DB::transaction(function () {
DB::table('users')->where('votes', '<' , 0)->update(['votes' => 0]);
});
Official Laravel doc says
The update method should be used to update existing records in the database
But transaction seems more handful that can react to exceptions.
So in what scenarios one is better than the other?
The DB::update() is for raw sql queries on the other hand DB::table()->update is for query builder. Query builder is much more efficient as it prepares and binds the statements itself.
The question has been answered here
This question already has answers here:
Oracle DB: How can I write query ignoring case?
(9 answers)
Closed 4 years ago.
I am working with database where i need to retrieve distinct values. Example [English enGLish english ....] all this should be displayed as English only. Can anyone tell me how to achieve this.
Thanks in advance
Looks like you need function initcap():
demo
select distinct initcap(column_name) from your_table
This is a Laravel problem - I tried to ask earlier but I am not sure I expressed myself well.
I have a bunch of rows and I would like to group the rows by year and month in descending order and then display all rows contained in each grouped month going backwards in time.
I have an old code of ten years which does the job well - but I am moving it to Laravel and I am doing okay on almost all queries and views but just cannot get this to work.
The problem is that it does not display the years and months in descending order and that I am unable to pass each row contained in the month grouping to the view.
I have tried arrays/collections/blade#foreach and I am a bit out of solution now, so I humbly request assistance!
This question already has answers here:
Oracle: function based index selective uniqueness
(2 answers)
Closed 8 years ago.
I have a table with a column IS_LOGGED which takes only two values 'Y' or 'N'
I want to have a Function based index on the column IS_LOGGED where value is 'Y'.
The purpose of index is to list all entries in an easy and fast to access manner.
Suppose you get a 1500 pages thick book to read with an index listing only specific chapters. What is the use of such an index?
I don't think you need a function based index here. Simply create an index and modify your queries to include IS_LOGGED = 'Y' clause.
This question already has an answer here:
How to check if a columns value was explicitly specified in a PL/SQL BEFORE UPDATE trigger?
(1 answer)
Closed 8 years ago.
Is there an efficient method to identify which column has changed in a table in Oracle using a trigger? How to check if only one column (of interest) or all other columns also changed?
As the post Alex Pole pointed in your comments states, you could use the UPDATING function.
But you can also develop different triggers for updating specific columns with "BEFORE UPDATE OF" clause, witch is the optimal option if there is no code to share among the actions for the involved columns.