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 8127191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:26:21+00:00 2026-06-06T07:26:21+00:00

I have a table which contains TV Guide data. In a simplified form, the

  • 0

I have a table which contains TV Guide data.

In a simplified form, the columns look like the following…

_id, title, start_time, end_time, channel_id

What I’m trying to do is create a list of TV shows in a NOW/NEXT format. Generating the ‘NOW’ list (what’s currently being broadcast) is easy but trying to get a list of what is showing ‘NEXT’ is causing me problems.

I tried this…

SELECT * from TV_GUIDE where start_time >= datetime('now') GROUP BY channel_id

Sure enough this gives me one TV show for each TV channel_id but it gives me the very last shows (by date/time) in the TV_GUIDE table.

SQL isn’t my strong point and I’m struggling to work out why only the last TV shows are returned. It seems I need to do a sub-query of a query (or a query of a sub-query). I’ve tried combinations of ORDER BY and LIMIT but they don’t help.

  • 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-06T07:26:23+00:00Added an answer on June 6, 2026 at 7:26 am

    I believe that you first must select the couples (channel_id, ) from TV_GUIDE, based on your criteria.
    Then, you will display those records of TV_GUIDE which match those criteria:

    SELECT source.* from TV_GUIDE AS source
    JOIN (SELECT channel_id, MIN(start_time) AS start_time
        FROM TV_GUIDE
        WHERE start_time >=  now() GROUP BY channel_id ) AS start_times
    ON (source.channel_id = start_times.channel_id 
        AND source.start_time = start_times.start_time)
    ORDER BY channel_id;
    

    This first selects all shows with minimum start time, one for each channel, thus giving you the channel id and the start time. Then fills in the other information (MySQL sometimes lets you retrieve that from a single query, but I feel it’s a bad habit to acquire – maybe you add a field and it won’t work anymore) from a JOIN with the same table.

    You might want to add an index on the combined fields (start_time, channel_id). Just to be on the safe side, make it a UNIQUE index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains the following columns: UniqueID remote_ip_addr platform I want
I have table which contains columns like SiteID (identity_Col) SiteName POrderID Location Address Cluster
I have table which contains 2 date fields. Like: id from to --- ----
I have a table which contains data in different languages. All fields are nvarchar(max).
I have table which contains data along with created on date. I want to
I have table Users which contains columns Login and Phone and I have table
I have table Users which contains columns: id, name, points, extra_points. How can I
I have a table which contains a two column( start_time and end_time ).I am
I have a table which contains members signups and I would like to be
I have a table which contains hourly records (spanning multiple days). What I'd like

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.