Web Analytics Made Easy -
StatCounter count (*) from (select ....) - CodingForum

Announcement

Collapse
No announcement yet.

count (*) from (select ....)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • count (*) from (select ....)

    Code:
    SELECT  Count(*)  FROM (SELECT * FROM table)
    --> Every derived table must have its own alias

    How to do this ?

    EDIT:

    huh, cant tell why now works.
    Code:
    SELECT  Count(*)  FROM (SELECT * FROM table) as Z
    Last edited by BubikolRamios; Apr 5, 2009, 02:54 AM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    As the message said, your DERIVED TABLE (which is what that
    SELECT * FROM table
    is) needed an alias. Yes as Z is indeed an alias.

    NOW...

    Explain to us why you thought you *needed* a derived table????

    Why didn't you just code
    Code:
    SELECT COUNT(*) FROM table
    ????
    Be yourself. No one else is as qualified.

    Comment


    • #3
      explanation:
      (SELECT * FROM table) is just a demo

      real sql isn't simple as this, in fact it return something like this, forinstance 1 count column which is already grouped . including bunch of joins, and one complicated tip from you Old pedant :-).... -->

      3
      1
      6
      1

      and what I need is count of resulting rows, i.e. 4
      Last edited by BubikolRamios; Apr 5, 2009, 03:57 AM.
      Found a flower or bug and don't know what it is ?
      agrozoo.net galery
      if you don't spot search button at once, there is search form:
      agrozoo.net galery search

      Comment


      • #4
        Okay, makes sense. But anyway, I guess as you noted, all you needed was the AS clause.

        This is, by the by, a MySQL requirement. SQL Server doesn't require it, for example.

        Yet another of the quirky differences between different dialects of SQL.
        Be yourself. No one else is as qualified.

        Comment

        Working...
        X