|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
count or select ONLY the populated rows in a column?
I'm trying to COUNT the number of populated rows within a column named, 'column_03', but first instead of using COUNT i'm using SELECT to see where the numbers are coming from.
with the following code....... first i'm selecting from 'column_01' then i'm selecting from 'column_02' finally i''m selecting from 'coulmn_03, (but only rows that are populated with info) Code:
SELECT column_03 FROM table_name WHERE table_name.column_01 = 'IN'' AND table.name.column_02 ='GENER" the result is a total number of 10 records. i can see that 'column_03' has 6 rows that are populated and 4 rows are empty. now what i want to do is select only the 6 rows that are populated, once i now how to do that i can then use COUNT. after searching through google i came up with this variation..... Code:
SELECT (NULL) column_03 FROM table_name WHERE table_name.column_01 = 'IN'' AND table.name.column_02 ='GENER and that didn't work, i get a result thats kinda weird, but logically thinking about it ...if it did work, by specifying NULL would I be asking to SELECT the rows that are EMPTY??? doesn't seem to be asking for just the populated rows???? i didn't realise that such a simple request could be so hard! |
|
#2
|
||||
|
||||
|
Wouldn't you want to just do something like this?
Code:
SELECT COUNT(*) FROM table_name WHERE table_name.column_01 = 'IN' AND table.name.column_02 ='GENER' AND column_03 IS NOT NULL
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
i've used the COUNT and SELECT variations and i get the same results.
this one still selects 10 rows, 4 that i can see are empty and 6 that have (alpha string) values Code:
SELECT column_03 FROM table_name WHERE table_name.column_01 = 'IN'' AND table_name.column_02 ='GENER" AND table_name.column_03 IS NOT NULL this one provides a total count of 10 Code:
SELECT count(*) FROM table_name WHERE table_name.column_01 = 'IN'' AND table_name.column_02 ='GENER" AND table_name.column_03 IS NOT NULL do you think it could be something to do with the way column_03 is set up, as NULL or NOT NULL?? initially it was set up as NOT NULL so i copied the table structure changing column_03 to NULL, then re-imported the data ....but i get the same results on both types of columns. I just don't understand whats going on??? |
|
#4
|
|||
|
|||
|
for all you crazy kids out there .....i solved it with this....
Code:
SELECT column_03 FROM table_name WHERE table_name.column_01 = 'IN' AND table_name.column_02 ='GENER' AND table_name.column_03 <> '' |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > count or select ONLY the populated rows in a column? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|