Skip to content

Tag: laravel

How to use this laravel query builder for this SQL Query

I have this query: SELECT `topic_posts`.*, `users`.`id` AS `adminID`, `users`.`name` as `adminName` FROM `topic_posts` INNER JOIN `topics` ON `topics`.`id` = `topic_posts`.`topic` INNER JOIN `users` ON `users`.`id` = `topic_posts`.`player` WHERE `users`.`playerAdminLevel` > 0 AND `topics`.`type` = 0 GROUP BY (`topic_posts`.`id`) And I want to use in Laravel, something like: $result = DB::table(‘topic_posts`)->join..etc And also, to use ->paginate(20) How can I do

SQL query for last 365 days report

I have a reports table with the following structure : I want a SQL Query to get the report for the last 365 days by following conditions : Group dates if the same date is repeated. The days which the report is not available for the last 365 days, I need those days added to the result rows with 0

Display all data which are between these dates

So currently, I am trying to display a list of items which are not between date X and date Y. Let us assume that book_date_start = 2021-06-15, and bookdate_end = 2021-06-20 This is my current query: So based on this So basically as I was writing the above out, I realized that my query is WRONG, and since 2021-06-13 is

How to insert data from one table to another in laravel?

I have two tables, visitors and in. visitors contains columns, Name, Number, Purpose, and Datetime. in contains Name, Number, and InTime. I want to fetch all the values from the visitors table into in. I have tried copying the data from visitors to in, however, if I add new rows into the visitors table, those new rows won’t be reflected

1064 You have an error in your SQL syntax; check the manual … for the right syntax to use near ‘WHERE reviews.yes_no = yes

I want to optimise the queries on my project and after many tentatives of using eager loading with datatables i just give up because there was no query reducing at all. Anyway now Im trying to achieve that using join, but the problem is that using WHERE clause in DB::RAW it gives me the following error: “Exception Message:nnSQLSTATE[42000]: Syntax error

MySql Group By Count item count Distinct

I have a table looks like Here user id 1 exist in level 1 and level 2 Now when we count group by level then in counting we want ignore user_id 1 from level 1 cause it exist another group. we want to consider only one group existing and higher group. I have done only group count but cant understand