Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MySQL sql statement question

MySQL sql statement question

Scheduled Pinned Locked Moved Database
databasemysqlquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    I have the following statment:

    SELECT * FROM member_channels WHERE member_channel_address = param_member_channel_address;

    that's member_channels where I also have member_channel_id (primary key) In member_posts, I have member_channel_id.. I want to count total posts linked to member_channel_id and I want to display it as count field in the above statement..

    J 1 Reply Last reply
    0
    • J Jassim Rahma

      I have the following statment:

      SELECT * FROM member_channels WHERE member_channel_address = param_member_channel_address;

      that's member_channels where I also have member_channel_id (primary key) In member_posts, I have member_channel_id.. I want to count total posts linked to member_channel_id and I want to display it as count field in the above statement..

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Something like the following SELECT *, count(p.member_channel_id) FROM member_channels c, member_posts p WHERE c.member_channel_address = param_member_channel_address and c.id = p.member_channel_id

      J 1 Reply Last reply
      0
      • J jschell

        Something like the following SELECT *, count(p.member_channel_id) FROM member_channels c, member_posts p WHERE c.member_channel_address = param_member_channel_address and c.id = p.member_channel_id

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        thanks but there is one problem. when member_post has no rows linked to the same member_channel_id, it will not return anything but I want it to return the details with zero count

        L 1 Reply Last reply
        0
        • J Jassim Rahma

          thanks but there is one problem. when member_post has no rows linked to the same member_channel_id, it will not return anything but I want it to return the details with zero count

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          jrahma wrote:

          but there is one problem.

          We call it a JOIN. Try Visual Representation of SQL Joins[^] :)

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups