Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:30:41+00:00 2026-06-03T10:30:41+00:00

Solution: $query = $this->db->query( SELECT *, SUM(views.times) AS sum FROM channel RIGHT JOIN video

  • 0

Solution:

$query = $this->db->query("
   SELECT *, SUM(views.times) AS sum
   FROM channel
   RIGHT JOIN video
   ON channel.channel_id = video.channel_id
   LEFT JOIN user
   ON channel.user_id = user.user_id
   LEFT JOIN views
   ON channel.channel_id = views.channel_id
   GROUP BY channel.channel_name
   ORDER BY sum DESC
");

I have a query that returns a list of items.

function getfrontpage(){
    $this->db->select('*');
    $this->db->from('channel');     
    $this->db->join('video', 'channel.channel_id = video.channel_id' , 'right');
    $this->db->join('user', 'channel.user_id = user.user_id');
    $this->db->group_by("channel.channel_name"); 
    $query = $this->db->get();
    return $query->result();
}

Now i’m trying to order these with the SUM from another table, how can i achieve this?

Here is a picture from that table:
view table

I want the results to be sorted by the SUM of the total of “times” for each “channel_id”

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:30:42+00:00Added an answer on June 3, 2026 at 10:30 am

    I would suggest to run this through $this->db->query() instead.

    It’s nice to fetch simple values through CodeIgniters AR functions. But at some situations it’s simply easier to build query strings instead.

    In your case:

    $query = $this->db->query("
    SELECT channel_id, SUM(times) AS sum
    FROM channel
    GROUP BY channel_id
    ORDER BY sum DESC
    ");
    

    You can also escape most values through db->query()!

    $this->db->query("
    SELECT name
    FROM table_name
    WHERE id = ?
    ", array(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query as follows. select strftime('%Y-%m',A.traDate) as Month,sum(A.TraAmt) as Total,C.GroupType from TransactionTbl
I have a query like this: select data_name into v_name from data_table where data_table.type
Suppose I have a query like this - SELECT * FROM OPENXML(@i, '/root/authors', 2)
I have this working query which works correctly: select problems.problem_id , problem_title , sum(
I have the following query: SELECT Account, Unit, SUM(state_fee), Code FROM tblMta WHERE MTA.Id
I'm having trouble figuring out the solution to this SQL query. Schema Edit :
I have created a JPQL like this: select sum(c.field1) field1, sum(c.field2) field2, sum(c.field3) field3
I have the following query, in the top select statement (sum(l.app_ln_amnt)/count(l.app_ln_amnt)) works well but
Is it possible to force case-sensitive for a query? Mine sounds like this: SELECT
DB: Sql Server 2008. I have a really (fake) groovy query like this:- SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.