Count(*) Vs count(1)

Hi
Can some one tell me the difference between count(*) and count(1) in SQL
I can see count(1) taking a lot of time compared to the other
TIA

Can some one tell me the difference between count(*)
and count(1) in SQL
I can see count(1) taking a lot of time compared to
the other
SQL is a language. There is no speed associated with it intrinsically.
What database vendor are you using?
And how are you timing it?
And did you profile it?

Similar Messages

  • What is the difference between count(*) and count(1)

    what is the difference between count(*) and count(1)

    Hi,
    903830 wrote:
    some say count(1) is faster and some say count(*), i am confused about count function?In the link provided by Prakash :
    prakash wrote:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156159920245
    You can read :
    Followup   August 31, 2001 :
    I'll have to guess, since you don't say, that you are using 7.x and before when count(*) and count(1) were different (and count(1) was slower). In all releases of the databases for the last 4-5 years, they are the same.
    Don't waste your time on that.
    ;-)

  • Count(*) VS Count(ColumnName) VS Count(1)

    Can some explain which one is better,
    Count(*)
    Count(ColumnName)
    Count(1)
    I think they are same, any one has any other opinion.

    Count(*)
    Count(ColumnName)
    Count(1)
    The diference that's
    Count(*), check all table' columns of which can more slowly
    Count(ColumnName), Only count data of especificaded column, no check null fields
    Count(1), check only the table's column 1
    The use depends on the sitacion, and therefore the best performance, depends on the proper use.

  • Count(*) VS count(indexed_column_name)

    Hi, after a lot of reading here in the forum and the "ask tom" site, I can see that count(1) and count(*) are on the same, count(*) prove to be even faster sometimes. My question is: This is the same for indexed columns declared inside the count clause? Example:
    select count(*) from Person p, (lots of nasty joins from here...)
    VS
    select count(indexed_primary_key_person) from Person p, (lots of nasty joins from here...)
    From my reading, that could be more efficient in older oracle version (7 and before). What about today? Same speed? And is this information write in some FAQ or book?
    Thanks in advance,

    An indexed column can still contain NULLs, so the count vs count(*) may not be the same.
    SQL> create table t as select * from all_objects;
    Table created.
    SQL> create index t_idx on t (subobject_name);
    Index created.
    SQL> select count(*) from t;
                COUNT(*)
                   73045
    SQL> select count(subobject_name) from t;
    COUNT(SUBOBJECT_NAME)
                     2407Of course, this has nothing to do with indexes.
    A primary key column will give you the correct count. In fact, if you do an explain plan on 'select count(*) from t' where the table has a primary key, Oracle will probably get the count from the index and never touch the table.
    SQL> alter table t add constraint t_pk primary key (object_id);
    Table altered.
    SQL> explain plan for
      2  select count(*) from t;
    Explained.
    SQL> @xp
    | Id  | Operation             | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     1 |   112   (0)| 00:00:02 |
    |   1 |  SORT AGGREGATE       |      |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| T_PK | 76047 |   112   (0)| 00:00:02 |
    ----------------------------------------------------------------------

  • Help! To design a counter for counting clocks

    Dear all,
    I want to design a counter that count all clocks of a square wave. I have tried but I am getting stuck somewhere. Here's attached the file that I started. In this project, my objective is to use NI-USB-6008 to send a square wave to an external oscilloscope. That square wave has to be self-controlled such that nth first clocks have  a certain frequency different to the next (n+1, .....,m) clocks. As part of that, I need to use a counter that I designed myself.
    Actually, I have the C++ codes for that:
    int count=0;
    if(result==1)
    count++;
    This is just the section that I want
    Attachments:
    DigOutFuncAuto.vi ‏180 KB

    Hello,
    I am a bit confused about your application, are you trying to count (input) clock edges or generate a clock signal with your 6008. If you want to count digital edges with the USB-6008 you can use the counter on the 6008 to count these edges; an example in the example finder exists already and can be found in the location shown below. If you want to generate this varying clock signal, it will be difficult with a USB-6008 since it software timed and updates to the digital line will depend on the updates over the USB bus. If you can clarify your application a bit, I may be able to make some suggestions.
    Eric
    Eric Liauw
    AE Specialist - Automated Test | CLD | CTD
    National Instruments

  • Reset clock count/encoder counts

    Is there a way to programatically reset the clock count using labview? I am using an encoder and an e series DAQ board. When I am counting with the encoder, I come to a point where I would like to reset it to zero. I see that the examples all show that the count is reset after the loop is complete, but I would like to reset it during the loop to use it as a positioning tool. Reset to zero then start counting again from that point. Is this possible? Thanks.
    Using Labview 6.1 and MIO16E DAQ Board.

    Use the "Counter Control.vi" (Data Acquesition-> Counter->Advanced Counter). With the control code 1 you can resets the counter. Alternatively you may use the VI with control codes 4 and 2 which disarms and arms the counter again ("If you follow a disarm with another arm, then the acquisition restarts from the beginning"). That should do.

  • Count(1),count(*),count(rowid)

    i found from oracle book that
    count(1)--fast
    count(*)--slow
    count(rowid)--fast
    but in this forum lot is said about the count function.and i.e count(1)=count(*)=count(rowid)
    then why even in the book fast & slow is mentioned.
    so does oracle internally converts count(*) to count(1) or really fast and slow comes into picture
    thanks

    If you read the various threads on this forum as well as on AskTom, you will see that Oracle internally converts count(<some constant>) to count(*) as part of the query rewrite, so they are essentially identical.
    When you start counting on rowid or particular columns then things can differ a little, but essentially ... not much.

  • Differenct between count(0), count(1) and count(*)...???

    Hi,
    Please clarify the difference b/w count(0), count(1) and count(*)...???.
    SQL> set timing on
    SQL> select count(0) from trade
    2 /
    COUNT(0)
    112158506
    Elapsed: 00:00:03.08
    SQL> ed
    Wrote file afiedt.buf
    1* select count(1) from trade
    SQL> /
    COUNT(1)
    112158506
    Elapsed: 00:00:02.01
    SQL> ed
    Wrote file afiedt.buf
    1* select count(*) from trade
    SQL> /
    COUNT(*)
    112158506
    Elapsed: 00:00:02.03
    SQL>
    Is there any differences??
    Thanks
    SATHYA

    Looks the same to me
    admin@10gR2> create table big_table as select * from all_objects;
    Table created.
    admin@10gR2> set autotrace traceonly
    admin@10gR2> alter system flush shared_pool
      2  /
    System altered.
    admin@10gR2> select count(1) from big_table;
    Execution Plan
    Plan hash value: 599409829
    | Id  | Operation          | Name      | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |           |     1 |   185   (2)| 00:00:03 |
    |   1 |  SORT AGGREGATE    |           |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| BIG_TABLE | 72970 |   185   (2)| 00:00:03 |
    Note
       - dynamic sampling used for this statement
    Statistics
            322  recursive calls
              0  db block gets
            947  consistent gets
              0  physical reads
              0  redo size
            413  bytes sent via SQL*Net to client
            381  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
              1  rows processed
    admin@10gR2> alter system flush shared_pool
      2  /
    System altered.
    admin@10gR2> select count(*) from big_table;
    Execution Plan
    Plan hash value: 599409829
    | Id  | Operation          | Name      | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |           |     1 |   185   (2)| 00:00:03 |
    |   1 |  SORT AGGREGATE    |           |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| BIG_TABLE | 72970 |   185   (2)| 00:00:03 |
    Note
       - dynamic sampling used for this statement
    Statistics
            322  recursive calls
              0  db block gets
            947  consistent gets
              0  physical reads
              0  redo size
            413  bytes sent via SQL*Net to client
            381  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
              1  rows processed

  • Difference count(*) and count(1)

    Is there any difference between count(*) and count(1)
    when write select count(*) from emp
    and select count(1) from emp
    output of both query are same plz tell me the difference
    thnks

    Just as a side note. Count does behave differently if you count by a column.
    ex.
    select count(*) from perf_results;
       COUNT(*)
           3222
    select count(fy_year) from perf_results;
    COUNT(FY_YEAR)
              3207If a column has a null value it will not be counted

  • Reoccuring errors with volume file count, directory count, etc...

    I'll give a little back story...
    I purchased a new MacBook Pro 17" with OS X Lion (10.7.2) preinstalled back in January of this year (2012).  I migrated my user accounts from my old MacBook Pro 15" (2008) running OS X Snow Leopard.  Almost right away I started having issues of all sorts, including Admin accounts that wouldn't allow me admin priveledges, hidden user groups, apps that wouldn't run, multiple obscure error messages and a host of other issues.  After scouring forums like this one I used Disk Utility and not only discovered innumerable permission errors but also disk errors like these:
    Invalid volume file count
    (It should be 1656658 instead of 1656636)
    Invalid volume directory count
    (It should be 345764 instead of 345743)
    Invalid volume free block count
    (It should be 69344839 instead of 69355225)
    Volume header needs minor repair
    Disk Repair would correct the ACH/permission errors and above-noted disk corruption, but only temporarily.  After repairs I would reboot and be met with all of the same problems in the migrated accounts.  Over the following days I reinstalled OS X Lion at least three or four times, completely wiping the 750 GB hard drive before two of those reinstalls (even doing one-pass reformatting on one of those instances).  After reinstalling the OS, I would reinstall from TimeMachine and be met with all of the same problems again.
    I then brought my machine in to the Genius Bar where, after more than two-and-a-half hours they declared it to be an unknown issue that must be related to defective hardware and replaced my entire machine.  But wait - there's more!
    After getting home and moving my old accounts back over from TimeMachine all the same issues began reoccuring.  After at least two more OS reinstalls later I discovered that uninstalling Norton Internet Security seemed to fix some problems.  However, running Disk Utility still returned results like those listed above...
    Then there were the failed attempts at upgrading from 10.7.2 to 10.7.3 which  hung at the end the first two times and required complete OS reinstalls from the Recovery HD.  Several more headaches later I eventually I managed a sucessful upgrade.
    But still I find myself with a machine that stalls on boot-up at least once or twice a week, necessitating a power-off to interupt the process.  After each of these instances I run Disk Utility and get more of the same...
    Checking volume information.
    Invalid volume file count
    (It should be 1656658 instead of 1656636)
    Invalid volume directory count
    (It should be 345764 instead of 345743)
    Invalid volume free block count
    (It should be 69344839 instead of 69355225)
    Volume header needs minor repair
    The volume [...] was found corrupt and needs to be repaired.
    And now, this morning, after a month or two of all that... and after installing the Java Security Upgrade last night, I can't get into my accounts at all.  On first boot-up it hung for 20 minutes before I shut it down.  After running Disk Utility from Recovery Drive and repairing the drive I rebooted and got the log-in screen.  I clicked on my user icon, typed the correct password, was shown they white/grey screen for a few flickering seconds then was brought back to the log-in screen.  I rebooted to the Recovery Disk, ran Disk Utility, saw all the same errors again, repaired the disk, rebooted and got the same problems with logging in again.
    I've repeated this cycle five times today, as both a normal boot-up and in "Safe Mode" all with the same results.  I've repaired the disk using Disk Utility from Recovery Disk as well as accessing the disk in Target Mode, and always there are the same errors needing to be repaired.
    I don't buy that I'm dealing with a hardware issue.  My antivirus and security software are all up-to-date.  What the heck is going on?  Why do I keep having these disk problems?  Why can't I access my accounts anymore?  Why does it keep hanging during boot-up?  Why am I about to throw the machine out my bedroom window?

    WithoutID wrote:
    I don't buy that I'm dealing with a hardware issue.
    You have a software issue carried over from the previous computer likely caused by Norton and perhaps some other issues related to recent malware.
    Your going to need to copy your users data folders only to a external drive and disconnect everything,
    command r boot into Recovery,
    DU erase (with Zero) your Lion partition,
    install Lion fresh from Apple,
    setup with the same name (important),
    Software update,
    install all your programs from fresh sources,
    and return files from the external drive manually into their respective folders
    in that precise order.
    and for good performance for a long time, try not to go over 50% of the drive filled, but certainly not more that 75%
    Do not use migration or TimeMachine restores.
    This is known as a Fresh Install, where everything is brand spanking new and only vetted files are returned.
    It's a pain I know, the problem with too much automation, the crap seeps in and ruins everything.
    I don't migrate nothing, I like my machines to work perfectly.
    https://discussions.apple.com/docs/DOC-3046
    https://discussions.apple.com/community/notebooks/macbook_pro?view=documents

  • Counter Output/Counter Input PXI Signals Behaving Erratically

    Question for all your LabVIEW guru's out there,
    I am running a frequency loopback test using the NI PXI 6229 MIO DAQ card.  I am generating a "Counter Output" pulse train signal which feeds through my device under test and then back out of my device under test and back into the PXI 6229 for a "Counter Input" frequency measurement.  Both the "Counter Output" and the "Counter Input" are assigned different PFI lines using DAQmx in LabVIEW.
    I have 4 lines to test on my DUT.  All four lines run this same frequency measurement but with different PFI lines on the PXI 6229.  Each line is test independently.
    This is my setup for the 4 lines:
    Path 1: P2.0 (Counter Output - Pulse Train) -> DUT (Device Under Test) -> P2.1 (Counter Input - Frequency Measurement)
    Path 2: P2.2 (Counter Output - Pulse Train) -> DUT (Device Under Test) -> P2.3 (Counter Input - Frequency Measurement)
    Path 3: P2.4 (Counter Output - Pulse Train) -> DUT (Device Under Test) -> P2.5 (Counter Input - Frequency Measurement)
    Path 4: P2.6 (Counter Output - Pulse Train) -> DUT (Device Under Test) -> P2.7 (Counter Input - Frequency Measurement)
    where:
    P2.0 = PFI8
    P2.1 = PFI9
    P2.2 = PFI10
    P2.3 = PFI11
    P2.4 = PFI12
    P2.5 = PFI13
    P2.6 = PFI14
    P2.7 = PFI15
    I have a LabVIEW VI which generates the "Counter Output" and reads the "Counter Input" frequency.  I am seeing weird behavior from the PXI 6229 card. I can test "Path 1" and "Path 2" and the frequency I read is what I generated. No issue there. However, when I test "Path 3" and "Path 4" the frequency measurement is erratic.  The readings are two different frequencies repeated over and over again and none of those frequencies are the expected frequency which was generated out of the "Counter Output."  If I reset the card, and start by testing "Path 3" and "Path 4" the frequency readings are correct and the erratic behavior is gone.  However, when I try to then test "Path 2" and "Path 1" now those lines have the erratic frequency issue. I can continue resetting the card and see same issue. The PFI lines that I test first will always pass.
    To summarize:
    Steps Taken:
    1. Test Path 1 = SUCCESS
    2. Test Path 2 = SUCCESS
    3. Test Path 3 = Erratic Frequency (Two Frequencies repeated over and over again in my frequency results array)
    4. Test Path 4 = Erratic Frequency (Two Frequencies repeated over and over again in my frequency results array)
    5. Reset the PXI 6229 Card
    6. Test Path 3 = SUCCESS
    7. Test Path 4 = SUCCESS
    8. Test Path 3 = Erratic Frequency (Two Frequencies repeated over and over again in my frequency results array)
    9. Test Path 4 = Erratic Frequency (Two Frequencies repeated over and over again in my frequency results array)
    I am wondering if Port 2 (P2.0-P2.7) on the 6229 card has certain dependecies and this is why I am seeing issues.  I am trying to get around this issue so that I don't have to always reset the card.
    Are P2.0-P2.3 (PFI8-PFI11) and P2.4-P2.7 (PFI12-PFI15) treated differently or require different setup?  How do I resolve this issue?
    Thanks so much!

    I have a theory...
    The DAQ card follows a policy called "lazy uncommit" wherein the terminal used for the output will continue to be connected to the counter even after the task has completed (until the terminal is needed for something else).  So as you run more tests, the counter output will end up driving more lines.  This behavior should be easy enough to confirm.
    As the DAQ card drives more lines, I'd imagine this affects the actual signal.  You could scope it to check, but it sounds like either the rise/fall times are becoming longer or some extra noise is being introduced on the line.  
    The readings are two different frequencies repeated over and over again and none of those frequencies are the expected frequency which was generated out of the "Counter Output."
    This implies you are picking up an extra edge during transitions--this isn't too uncommon if the signal is noisy since there is no built-in hysteresis on the DAQ card.  I would expect the measured frequencies to have periods that sum to either the full period or the semi-period of your actual signal (depending on how many duplicate edges are detected).
    Suggestions are as follows:
    To stop the DAQ card from driving multiple PFI lines, it would probably be easiest to just programmatically reset the device in between your tests (using DAQmx Reset Device).  If you can't reset the device (e.g. because you are running some other task that can't be interrupted) then you can instead configure a dummy task that uses the PFI line in question as an input.
    To stop the DAQ card from picking up multiple edges during transitions, you should configure a digital filter on the input terminals.  If you reset the device it sounds like this might not be necessary... it's up to you if you want to configure this or not.
    Best Regards,
    John Passiak

  • Using DAQ-assist to input a waveform; need help building a counter to count voltage "spikes"

    Hey all! I'm pretty new to labView and even newer to this forum, but its nice to meet you all...I hope that perhaps someone can help me with my problem.
    Allow me to begin by detailing the specifications of the problem.  I am an undergraduate student, and have a job doing research in a MEMS (micro/nanotech) lab.  The graduate student I am making this program for is working on biomedical applications;  eventually, the program will be connected to a microdevice that has a tiny channel in it, cut through a wee little capacitor, which blood will run through.  As red blood cells pass this capacitor, the voltage will spike; meaning that for each voltage spike, we can (and are trying to) count the number of red blood cells.
    However, I am still in the early developement of the program, so this above specific info is not that important.  Basically, I am using a function generator to input a waveform to the DAQ assistant of, say 500 mV.  I am trying to write a program that increments a counter every time I turn the voltage above say 550 mV (peak-to-peak), counting the number of simulated "spikes."  I have tried quite a lot to write a working program, and although I have not gotten it to work yet, I will post a screenshot of my most recent attempt HERE:
    I thank you in advance for any helpful tips, advice, or straight up assistance you may be able to give me.  Please ask me any clarifying questions about the program I wrote or the application, or anything.  Happy Friday! 

    Hey guys, it's been a while!  A lot of stuff has been happening in my life and I have had virtually no time to work on my LabView project.  
    I did create a LabView program based off IanW's reccomendation.  I am unsure of what exactly is going wrong, but when I run it, only a simple "snapshot" of a waveform from the DAQ shows up in the graph.  Even when I put the DAQ assist in a seperate while loop, the same thing happens.  I am including a screenshot of the project in case I am messing something entirely different up.  If you happen to read this, I really appreciate your help and thank you Ian! 
    I am also having a random issue with the filter signal VI.  So that background signals in the actual experiment do not read as "spikes" I have been instructed to include a high-pass filter in the VI.  However, everytime I use the high pass filter VI, it botches my signal and turns it into a bunch of noise!  I, nor my graduate mentor (who isn't too well-versed in LabView) have any idea why this is - we've tried using different types of filters to no avail.  
    Lastly, I would like to talk to Peter about a few questions I had abour LabView design.  In case you're still around, I will write another post later today with more detail.  In the meantime, I will try to find some of the example VIs about shift registers   All who read this have a great day!
    Attachments:
    count spikes pic.png ‏29 KB

  • Total count and count based on column value

    Primaryid  Id     Status
    1            50          1
    2            50          1
    3          50          1
    4            50          3
    5           50          2
    6            50          1
    7            51         1
    8            51         2Im looking for a query which returns total count of rows for id 50 and count of rows with status 1
    something like
    Id    count_total   count_total_status1
    50        6              4
    51        2              1Any suggestion ?

    SQL> select * from t4;
    PID ID STATUS
    1 50 1
    2 50 1
    3 50 1
    4 50 3
    5 50 2
    6 50 1
    7 51 1
    8 51 2
    已选择8行。
    SQL> select distinct id,count(id),sum(decode(status,1,1,0)) from t4 group by id;
    ID COUNT(ID) SUM(DECODE(STATUS,1,1,0))
    51 2 1
    50 6 4

  • Counting Requirement (Counting PO line items wrt PO No)

    Hi All,
    We have a requirement here . Suppose there are 2 Purchase orders Y & Z . "Y" purchase order has  5 line items as 10,20,30,40,50 . "Z" purchase order has 7 line items as 10,20,30,40,50,60,70 . now i want to count the number of purchase orders & no of line items . I.e output should be , for a particular month there are 2 purchase orders & 12 line items .
    Point will be awarded .
    Thanks,
    Deadlocks

    Hi Priya,
    thnx for the reply, just a small thing i wanted to ask,
    inside those two CKFs should i create a formula variable on PO header & PO item no ?
    Before this what i did was i created a CKF with constant 1 in it and then i applied exception aggregation as "total" and refrence characteristic as "PO header" & and "PO item".
    so instead of bringing item count as 12 it is bring 7 .
    Regards,
    Deadlocks

  • What happened to page count, word count and the toolbar at the top?

    Is there any way to edit the toolbar so that when I want to switch fonts I don't have to keep opening the toolbar on the side? (Is there anyway I can get the toolbar from the previous version back?)
    Also, is there a way for the page count and word count to show up and stay there for future documents? I had the word count appear and tried to save that as a template but when trying to open up new documents I have to go back and make it so the word count shows up again.

    What Peter said.
    Is there any way to edit the toolbar so that when I want to switch fonts I don't have to keep opening the toolbar on the side?
    Yes. Menu > View > Customize Toolbar... drag/drop the Fonts icon adjacent to the Comments icon on the Toolbar. The Fonts icon now becomes a toggle to show/hide the Fonts toolbox, which you could also produce with a command+T.
    (Is there anyway I can get the toolbar from the previous version back?
    No.
    Also, is there a way for the page count and word count to show up and stay there for future documents
    No. Available via Menu > View > Show Word Count. This produces a floating box at the bottom of your document. When you roll over it with your mouse, you have a selection of words, characters, and paragraphs. The word count excludes spaces.

Maybe you are looking for