Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Slow Select Count(*)


I have a table with 75,000 rows.

An Explain tablename shows this

'TourPartsID', 'int(10) unsigned', 'NO', 'PRI', '', 'auto_increment'
'TourPartID', 'int(10) unsigned', 'NO', 'MUL', '', ''
'TourPartTypeID', 'int(10) unsigned', 'NO', 'MUL', '0', ''
'Language', 'int(10) unsigned', 'NO', '', '0', ''
'XML', 'mediumblob', 'NO', '', '', ''

When I do a Select count(*) from table, it takes about 12secs to return my number. This is occuring in the QueryBrowser and from the .NET library when it calls the Stored Procedure that does the Select count(*)....

My only quess that is my last column is a MEDBLOB but since I am NOT indexing that, I would figure MySQL ignores it.




View Complete Forum Thread with Replies

Related Forum Messages:
Slow Select Using Count(distinct) In A Table Bigger Than 100000 Records
Recently I started using MYSQL in my enterprise. I made a table which has around 100000 records. The problems is that it is really slow.. Im trying to do a query in which I get the number of distinct users per day.

This is my query:

select date(startedDate) as mydate, count(distinct(Users)) as users from Mytable
group by mydate

It is really simple and it does it correctly but it takes one minute.. One minute is not too much time but i need to insert around 10 000 000 records and thats what worries me.....

View Replies !
Row Count Mismatch In Select Count(*) And Explain Select Count(*) From Table
mysql> explain select * from parameter;
+----+-------------+-----------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | parameter | ALL | NULL | NULL | NULL | NULL | 3354 | |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)

mysql> select count(*) from parameter;
+----------+
| count(*) |
+----------+
| 97 |
+----------+
1 row in set (0.00 sec)

View Replies !
Slow Count(*) On Many Indexed Rows
we have a 10 million rows table. One field 'stamped' is either 'yes' or 'no'.
About half the rows are 'yes' and half are 'no'.
Table is indexed on 'stamped'.
We just need the count on 'yes'.

SELECT count(*) from T where stamped='yes'

or <>'no' or >'n'... is very slow.

Is there a better approach / query to get a fast result?

View Replies !
Very Slow Select
The line indicated below from my php script is very slow (about 10 seconds). I have this field indexed so I thought that it would be much faster. Could someone tell me what might be wrong?

I'm also including the dump of the table definitions. This is a cd cataloging database.

Right now the filenames table is empty and I'm trying to populate it, but at the rate it's going it would take days. I have about 700,000 records in the 'files' table, but none in the 'filenames' table yet. Code:

View Replies !
Count(*) In A Select Returns "1". It Should Behave Like Select Count(*)
i'm trying to make a query work properly but I got lost:

SELECT *,count(*)
FROM cancons c, musics m, discos d, r_discos_cancons rdc
WHERE c.c_id_music = m.m_id
AND rdc.rdc_id_disc = d.d_id
AND d.d_id_music = m.m_id
AND m.m_id = 24
GROUP BY c_id

note:
cancons (ca) = songs (en)
discos (ca) = cd's (en)
music (ca) = musician (en)

don't worry for the WHERE part. i need it because of the foreign keys.
this query returns a table with the title of the song and some more data. on the right side, I get another column called "count(c_id)" with the number "1" in it for each row. That's supposed to be due to the "group by" clause, I think.

I'd like to get the table with the songs, as usual, and, with the same query, I'd like to get the total number of rows selected.

View Replies !
Slow Mysql Select *,
I have a sql table with more then 20,000 rows in a table called summary and when I run "select * from summary" it returns a exucutions time of 0.5 seconds in php which is kinda slow if you ask me, now I know that the * type for select isnt the fastest way to fetch data but its the most convenient for me.

View Replies !
SELECT WHERE IN To Damn Slow!
MySQL 5.1.30 x64
Windows XP x64 w/ latest updates.

-- Table Information --
InventoryKey = Primary Key
ContInvKey = Indexed
OwnerType + OwnerKey = Indexed

I am trying to do a SELECT WHERE IN and it's taking over 500 seconds to return results! This statement:

SELECT DISTINCT inventory.ContInvKey FROM inventory WHERE inventory.OwnerType = 1 AND inventory.OwnerKey = 18 AND inventory.ContInvKey > 0;

..takes 0.15 seconds to run and fetch 21 rows. However, if I do this statement:

SELECT * FROM inventory WHERE InventoryKey IN ( SELECT DISTINCT inventory.ContInvKey FROM inventory WHERE inventory.OwnerType = 1 AND inventory.OwnerKey = 18 AND inventory.ContInvKey > 0 );

.. it takes 500+ seconds to run and return 108 rows. Something is definitely wrong here. I can repeat it every time. I monitored the server ( I am the only connection ) and I see the server spike instantly when the query is received and then it flat lines. There doesn't appear to be any activity for 499.85 seconds. It's idle!

View Replies !
Slow SELECT Query INNODB Table
I have a couple hundred connections doing "SELECT [Char36 Field], [LongLong Field], [Long Field] FROM [Connection Specific Table] WHERE [NonIndexed VarChar36 Field]=[Value]". Notice that the table the select statement is being called on is unique to each connection. These tables have less than 10000 records, but this statement can sometimes take over an hour to execute.

It is an INNODB table.

View Replies !
Select Count Need Even 0 Count
I know I have seen the answer to this on here before (I think). I have a query that does a count and a join. I want to return records that are in one the one table and then their counts of how many times they have been clicked on, even if that count is 0.

Here is what I have:

Code:

SELECT
i.vin
, count( i.vin ) AS clicks
FROM inventory i
RIGHT OUTER JOIN statistics s ON s.vin = i.vin
WHERE
i.active = 1
GROUP BY i.vin
ORDER BY clicks ASC

View Replies !
SELECT COUNT(*) Or SELECT .. LIMIT 1?
If the purpose of a query is to see if atleast 1 record exists which would be faster?

SELECT COUNT(*) or SELECT .. LIMIT 1?

Both would use a WHERE clause.

View Replies !
SELECT COUNT(*)
I heard SELECT COUNT(*) can take a lot of resources if your counting a table with lots and lots of rows (hundred thousands, millions).
What if you add A WHERE clause to it? So something like:
SELECT COUNT(*) FROM table WHERE pid = ?
(pid is a index too btw)
IF adding a where clause, does it still scan the entire million plus rows, or only scans what is returned from the WHERE clause?



View Replies !
SELECT COUNT Or SUM()
Is there a difference between these two functions when your trying to gather how much a item appears in a database?
For example, which one will be better for a database w/ ~150,000 rows.

SELECT COUNT(category_id) FROM Threads WHERE category_id = '2'

Will return ~50,000 rows matching category 2

OR

SELECT SUM(category_id = '2') AS total FROM Threads
total will be ~50,000 rows also.

View Replies !
Select *, Count
I want to perform a select query, but it doesnt return the data i have in mind. The result should be all info in 1 row with the highest date plus a total of game_id
This is what works best sofar.

SELECT * , COUNT( game_id )
FROM `battle`
WHERE game_id =4
GROUP BY game_id
ORDER BY b_date DESC
LIMIT 1

Yet this doesnt return the last date but the first. Everything else i tried the count function returned 1 even though it should be 20 for example.
How can i solve this?

View Replies !
How To Use SELECT Count
how to use SELECT Count.

View Replies !
How To Select Count(*) And Something Else?
How do you select a count and another field without having to do two queries?

here's the query I'm using:-

SELECT
count(*) as totals, user

FROM user_posts
WHERE post='$md5'

View Replies !
Select Count(*) > @foobar
i have a query as follows and is unsure whether it is mysql or php:

$result = mysqli_query("SELECT COUNT(*) > @foobar AS status ....") where
it's suppose to get a one row value of either '0' or '1' (false or true)

if i were to do a SELECT COUNT(*) FROM...
i can use the php $row["COUNT(*)"] to refer to the index.

if i were to do a SELECT COUNT(*) AS status FROM...
i can use the php $row["status"] to refer to the index.

but in this case SELECT count > @foobar AS status,
refering to $row["status"] gives a empty value. however, running the
same query in mysql command prompt produces

+------+
|status|
+------+
| 1 |
+------+

php doesn't support such select statement? even array_keys($row) returns
empty.

View Replies !
SELECT COUNT (*) FROM Table
Newbie: SELECT COUNT (*) FROM table

When I run the above query from the command line, it works
fine.

When I run it from my powerbasic program, I can't seem
to get a reasonsible result.

What type of result does count return?
I get something that looks like this:
[ CHR$(133) ][ CHR$(21) ][ CH...

and the type is given as -5...

What is this type?

View Replies !
Select Count Syntax
im just a begginer in mysql. I have a problem on how can i place a result of a select statement query in a variable.
Here my select statement:
Select count(employee) from employee where empmonth =
1 and empyear = 2005;
This syntax is ok, it return a result of 123894 records. But what I want is to place the result in one variable that i can access inside the program so that i will run this select statement only once. I have tried this one syntax:
Select count(employee) into ll_count from employee
where empmonth = 1 and empyear = 2005;
but it return a result of zero record.

View Replies !
SELECT From 3 Tables (SUM, COUNT)
I have 3 tables:

table1: stores data with unqiue data_id number
table2: stores comments on the data, data_id is repeated
table3: stores votes on data_id

table1 example:
data_id - name
1 - joe
2 - peter
3 - mark

table2 example:
comment_id - data_id - comment
1 - 1 - joe is the best
2 - 1 - joe is not that good
3 - 1 - joe is bad

table3 example:
data_id - vote_up - vote_down
1 - 1 - 0
1 - 1 - 0
1 - 0 - 1


I need to have a SELECT query which selects joe's name, number of comments on joe (3), number of vote_up on joe=(2) and number of vote_down on joe=(1)

so from table2 a COUNT(comment_id) should occur, and on table3 a SUM(vote_up) and SUM(vote_down) should occur, I just don't know how to write the select statement ...

View Replies !
Two Table COUNT/select
I need to count the total (using SUM) from one column in one table, where the a condition is set from another table.
so far I've been striking out with this:
Code:

SELECT maxbid SUM(maxbid) FROM `probid_auctions` WHERE probid_categories.parent = 1853

View Replies !
Select COUNT(Name) Into PCount
i wanna count the total number of records by using this sql query...
Select COUNT(Name) into pcount from agent where agentcode = 'abc123';

this return me the total number of all records...

but when use this query:

Select COUNT(Name) into pcount from agent where Name = 'goh';

it return me the correct result....

may i know what is the problem and how can i solve it ??

View Replies !
Php, Mysql And Select Count
I use as the base an existing system, called PHPNuke. My programming work before are only on Assembler, C, C++, Perl and other Databases than MySQL. In PHPNuke and/or the MySQL Queries contained in it there are sequences for simple counting rows (without further processing). The following sequence is permanently used (as example):

$result = $db->sql_query("select * from "$prefix."_sometable where someting='$foo'");
$numrows = $db->sql_numrows($result);

I would make it rather in such a way:

$result = $db->sql_query("select count(*) as count1 from "$prefix."_sometable where someting='$foo'");
$numrows = intval($db->sql_fetchrow($result['count1']));

Now my hopefully not too stupid question. Is there a reason, why e.g. in MySQL large genuine result quantities must be formed, only in order number of lines to determine? I worked so far actually only with other databases. But it is quite possible that that makes any sense here - who knows? Knows here someone the mystery solution?

View Replies !
Select Count(*) Timing Out
I'm doing a "select count(*) from table1" and it takes forever, more then 3 minutes, for the result to come back. I'm running MySQL 5.0.19 on RedHat, I know my table has 51M records. When I run a "show table status where name='table1';" it returns the results in a few ms and gives me a record count. My table is defined below, I've tried forcing use of each index individually and forcing no indexes and all combinations and always the same result. Server is an intel based 64bit cpu with 16GB ram with pretty much nothing else going on......

View Replies !
SQL - Select Where Count Equals Zero
I have a table of products and a table of ratings so people can rate the products. I would like to select all the products the user has not rated. My thoughts are to join and count returning rows where count equals zero. But I am just not sure how to do it.

I have this that does the exact opposite of what I need, this returns just the row that I rated, I need all but the rows I rated, Make sense?

SELECT products.*, COUNT(ratings.id) AS count FROM products
LEFT JOIN ratings ON ratings.rateable_id=products.id
WHERE ratings.user_id = 10
GROUP BY products.id

(10 is the hard coded user id)

How can return ALL except the rows I rated?

View Replies !
Select All But Count Only Last 7 Days
The query should return a list of every DJ in the system and then show how many entries they put in within the last 7 days.

Currently what I have is only returning those who actually inputted data in the last 7 days, not including those who didn't and have 0 returned rows. I want it to show even people who have 0.

$query = "SELECT dj, COUNT(date) FROM playlist WHERE date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY dj";

The count is on date but doesn't really matter what is there since it just needs to count how many rows were found in the 7 day span....or does it?

View Replies !
Groupby Select Count...
i remember running this type of query but don't remember the right cmds..

i have something simple:

sections
---------
id | category | updated

threads
---------
id | title |

SELECT sections.id, sections.category, sections.updated, threads.title, COUNT(`threads.id`) AS total FROM sections
LEFT JOIN threads ON (threads.id = sections.id)
GROUP BY sections.id ORDER BY sections.updated, threads.id DESC

while(....)

everything works, sort of.. it's grouping everything fine and showing the count for each section but on each section it shows the first id/title for each of its sections. i want to sort the sections by `updated` DESC, and the last record for each section. i keep thinking the order by is fine, but it's obviously not the case..

View Replies !
Select Count Instr
SELECT COUNT(*) as cnt FROM xxx WHERE INSTR('yyy', '$') = 1 AND active='0'

I want to count all active records which has a $-sign as first caracter in field yyy!

View Replies !
Select Count(*) Issue
I have what I think is a simple SQL command getting unexpected results.

PHP code:

$query = "select count(*) as total_rows from part_master where mfg_id = '933' and part_no = '3601' order by part_no";

$result = mysql_query($query);

The result is total_rows = 0.

I run the same SQL from the DOS command window and get:

mysql> select count(*) as total_rows from part_master where mfg_id >= '933' and
part_no = '3601' order by part_no;
+------------+
| total_rows |
+------------+
| 1 |
+------------+
1 row in set (0.01 sec)

I'm running the latest versions of Apache, MySQL and PHP on a WinXP box.

View Replies !
Select Count Where Entries Are < 4
I want to count how many users have 4 or less entries in the table, so, so far i have
SQL
SELECT COUNT (*) AS fourLOCS FROM
(SELECT DISTINCT locsLog.locStudentID FROM locsLog)
which counts all the entries in the locsLog table and groups them by studentID so tells me how many users have made entries.
How do I limit this so it only gives me a total number of users who have made 4 or less entries. I think I'd need WHERE after the nested SELECT statement, but I don't know what I'd put in it. I tried
SQL
SELECT COUNT (*) AS fourLOCS FROM
(SELECT DISTINCT locsLog.locStudentID FROM locsLog)
WHERE fourLOCS <= 4
but had an error message (I'm doing it with an Access database with ASP and the message was 'Too few parameters. Expected 1').

View Replies !
SELECT Two COUNT Fields...
trying to select two count fields, but it's not working. there's no error in the query, but it seems not understand that I want it to count a userid from one table and then from another. here's the sql.

mysql_query("SELECT COUNT(acomments.user), COUNT(attractions.userid) FROM users JOIN acomments ON users.id = acomments.user JOIN attractions ON users.id = attractions.userid WHERE users.id = '$u'")

View Replies !
Particulary Select Count
My doTable in DB MYSQL:

Code:
IDGRAPH
1NULL
2123
3NULL
4NULL
5657
6NULL
I need count all records in the doTable and count the records NULL and NOT NULL, if possible with single query.

Output:

Total records = 6
Records null = 4
Records not null = 2

View Replies !
Question About Select Count(*) With Group By
suppose a hypothetical table called 'table' with one field called 'field' of
an arbitrary type.

select count(*) from table where field='value' group by field

produces no rows when run under the latest mysql. without "group by" it
produces 1 row.

is this according to the SQL standard or is this just a coincidence? in
other words, can i rely on this behaviour to deduce that there are no fields
with value 'value' in 'table'?

View Replies !
Select Count From A List Of Digits ??
I'm using php to extract data from postgres and print to browser. I have data that was input through checkboxes on a form - each checkbox had a different value but got pushed into the same column. Code:

View Replies !
Select And Count From Multiple Tables
i have two tables (providers and clients). Whenever I have a new user create an account, I want to check the count of each, and if it is 0, then the account can be created, otherwise they will get prompted for a new one.
What is the syntax for this? I was trying to do a select count(*) from table1, table2 where username=x, and for some reason it gives me a 5, even though there is only 1 entry.

View Replies !
Select Count With Limit Clause
trying to use count() statement to find duplicate content before insert new data into table... to do that I am using the following statement.

$query = "SELECT COUNT(*) AS total FROM table where picturelink='$picturelink[$i]'";

$result = mysql_query($query, $db);
$resrow = mysql_fetch_row($result);
$duplicate_check[$i] = $resrow[0];

As my database are getting bigger the select count statement taking longer time than I accepted ... and taking high cpu load.. So I planed to use

Limit clause with id desc .. as I wanted if the data is not duplicate withing last 5000 items , it could be proceed

So I write down following

$query = "SELECT COUNT(*) AS total FROM table where picturelink='$picturelink[$i]' Order By Id Desc Limit 0, 5000";

$result = mysql_query($query, $db);
$resrow = mysql_fetch_row($result);
$duplicate_check[$i] = $resrow[0];

But Limit clause having no effect on query... So please advice How I can use limit clause in select count or how I can optimize this whole statement to find out duplicate content before insert

View Replies !
Select Data And Count In One Statement
$q2 = "SELECT *, COUNT(album_id) AS total_albs FROM photo_albums WHERE user_id = $user_id AND deleted = 0 ORDER BY album_id DESC LIMIT 3"; ....

View Replies !
Select From 2 Tables With Count Command?
i have 2 tables called items and orders. i want a sql query which will count all orders to each items then select those items with 15 orders and more. i have done this but always an error:

Code:

SELECT itemid, orderid, ordername, itemname, count(orderid) FROM item i, orders o
WHERE
o.itemid=i.itemid
GROUP BY o.itemid HAVING COUNT(orders.orderid) > 15

View Replies !
Select Count From Multiple Tables
I want to select persons from a person table, and count from an "events", "trainings", and "leads" table, but I'm not able to figure out how to select distinct so that I get one person each and a count for how many times that person appears in each other table. My statement looks like this right now:

SELECT person.name, count(leads.lead_id), count(events.event_id), count(trainings.training_id) FROM person LEFT JOIN leads ON leads.person_id=person.person_id LEFT JOIN eligible ON eligible.person_id=person.person_id LEFT JOIN events ON events.event_id=eligible.event_id LEFT JOIN trainings ON trainings.event_id=events.event_id GROUP BY leads.lead_id, events.event_id, trainings.training_id

Is it even possible to do what I want?

View Replies !
Select Count (*) From Dabase.table
I have a problem with MySQL,

I am trying to execute a query similar that:

select count (*) from database.table

but the server return this error:

"ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that ..."

The query looks right, and if I try to execute the manuals example fails too.

can anyone help me?

In some place I read that exists a bug with some MySQL server versions, but I have try with several 5.0.27, 5.0.67, and some more.

My server is running over Windows XP.

View Replies !
How To Write A SELECT/COUNT + Other Fields
I have a table like so:

NAME | AGE
Joey | 21
Mary | 18
Lass | 43
Moch | 33
Joey | 23
Mary | 25
Mary | 65
Lass | 90

I what to write a single query that retrieves the total number of times a single name is found in the the table (Joey appears two times, Mary appears 3 times, and Lass appears two times) AND also retrieves each record.

SELECT COUNT(name) as name_total, name, age FROM persons_table WHERE 1

RESULT:
row#: name_total, name, age:
row1: 2, Joey, 21
row2: 3, Mary, 18
row1: 2, Lass, 43
row1: 1, Moch, 33
row1: 2, Joey, 23
row1: 3, Mary, 25
row1: 3, Mary, 65
row1: 2, Lass, 90

View Replies !
Non-Numeric Result From SELECT COUNT(*)
I'm using MySQL 4.1.11 and MyODBC 3.51.11.
I've a problem with SELECT COUNT(*) query.

I'm using mysql in ASP. I'm executing this query for example:

Select Count(*) as TotalMembers From Members; //with recordset("Totalmembers")
-- or --
Select Count(*) From Members; // with recordset(0)

but both of these queries aren't giving Numeric (Integer) results...
I'm cotrolling them with IsNumeric function by ASP. But it gives False result.

Also i cannot using mathematical operators such like +-*/ . Because result isn't numeric. And an error occurs.

If you know asp, could you try to use math operators with select count(*) result?

View Replies !
SELECT Count(xxx) AS Xxx Does Not Return Integer
i'm using the latest downloaded version of MySQL and am currently producing an app that is compatible with MySQL, MS Access and SQL 2000/2005, i've not really come across any problems making the app run across the 3 platforms (except for Access's wierd date syntax and MySQL's lack of a boolean field) but the followin is doing my head in:

If i run a count query such as

SELECT Count(CategoryID) AS CountCats FROM MyDownloads etc etc
CountCat = (Downloads.Fields.Item("CountCats").Value)

And then run an IF statement in my page code such as:

<% If CountCat = 0 Then .... %>

This works fine in Access and SQL as the Count value is seen as an integer, but in MySQL this chucks an error unless the code reads

<% If CountCat = "0" Then .... %>

Why is the count value not returned as an integer????? I cant understand that at all, what else could it be? I've seen another post on the forum along the same lines but with no answer to it.

This is grim as every page that uses a count needs to have an additional IF statement put on it to change the second IF statement if the database is detected as MySQL.

View Replies !
SELECT Sentece Choosing The Row With The MAX COUNT
i need to make a sentences that selects the row with the biggest count. goes something like this i make the COUNT of a column then i want to show only the biggest result.

View Replies !
Select Count(*) Showing -1 Rows.
In one of my preliminary tests with mysql, the below statement is showing the following way. What does -1 rows signify in the table with the select count(*) query. Is this (-1 rows in the query result) an error condition to be taken care ?.

bash-2.03# ./mysql -u test
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8 to server version: 5.0.18-max

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Code:

View Replies !
Select Count(*) Problem In Mysql Ver. 4.1
Difference mysql 4.0 and 4.1
My code:

strSelKoresOczek = "SELECT COUNT(*) il_Oczek";
+ " FROM dekretacje d";
+ " left join dekret_realiz dr on d.dekr_id=dr.dekr_id";
+ " left join rejestr_glowny rg on d.prej_id=rg.prej_id";
+ " left join jorg_slownik on
d.jorg_id=jorg_slownik.jorg_id";
+ " WHERE d.symb_rej='RKP' and d.p_rodz='Z'";
+ " and d.dekr_uzytk_id="+ALLTRIM(STR(giUzytkID));
+ " and d.data_czas_dekrwyc is null";
+ " and dr.dekr_id is null"

ok_wyk = SQLEXEC(gnConnHandle,strSelKoresOczek,"cur_sel_koresoczek")

In mysql control center select count(*) return value bigint(21)
Visual fox pro 8 In version 4.0.18 cur_sel_koresoczek.il_oczek is type
Numeric Visual fox pro 8 In version 4.1.16 cur_sel_koresoczek.il_oczek is type Char.

View Replies !
Trying To Select Values From Column And Count Each Different One
say my column values are thus:

1 | 1
1 | 2
1 | 3
1 | 4
2 | 1
2 | 2
2 | 3
3 | 1
3 | 2

my select is like this:

my $sth = $dbh->prepare("SELECT session_id, col2
From $table
");
$sth->execute;

while ( my @fields = $sth->fetchrow_array) {
print qq( $fields[0] );
}

I want to be able to show that there are three individual values (in col1) and that there are 9 values in col 2. I also need to show that (based on the number of values in col2 [relative to col 1]), that the average number is 3

Should I use select using UNIQUE (or some other value), or, should I select as shown but put it in a perl hash - or soemthing else?

View Replies !
SELECT COUNT Syntax Error
Have a syntax error with the following query ...
SELECT number COUNT(*) AS vessels FROM process_fleet WHERE uid=1
No idea what is wrong with the sytax... can only one see what I'm missing?

View Replies !
Select Query With Character Count
can you help me with creating a select query where the character count in a specific column is more than, say, 20 characters?

View Replies !
Multiple COUNT() In SELECT Statement
SELECT
COUNT(s01_Products.id)
FROM
s01_Products
LEFT JOIN
s01_Attributes
ON
s01_Attributes.product_id = s01_Products.id
LEFT JOIN
s01_Options
ON
s01_Options.attr_id = s01_Attributes.id
WHERE
(
s01_Products.active = 1
) AND (
(
LEFT(s01_Options.prompt,5) = "Small"
) OR (
LEFT(s01_Options.prompt,2) IN (28,30)
)
)


SELECT
COUNT(s01_Products.id)
FROM
s01_Products
LEFT JOIN
s01_Attributes
ON
s01_Attributes.product_id = s01_Products.id
LEFT JOIN
s01_Options
ON
s01_Options.attr_id = s01_Attributes.id
WHERE
(
s01_Products.active = 1
) AND (
(
LEFT(s01_Options.prompt,6) = "Medium"
) OR (
LEFT(s01_Options.prompt,2) IN (32)
)
)
And one for Large and Extra Large...

I would obviously like to combine all 4 queries in to 1 so that I can get my 4 counts in a single,

View Replies !
Select From Table And Count Results In Another
I have to tables table one containing airports and table two containg bookings. What I need to be able to do is count how many rows are returned form the booking table that matches each airport in the airport table.

So I might have in my airport table
Newcastle
Heathrow
Standstead
etc etc

and in my bookings table I have

Newcastle
Newcastle
Standstead
Heathrow
Heathrow

And what I want returned is
Newcastle(2)
Standstead(1)
Heathrow(3)

How can I go about doing this.


View Replies !
Doing A Select Statement With An Array To Get A Count
I posted this in the php forum and it was suggested I try it in the MySQL area instead. Sorry if this gets posted more than once.

So here is my problem. I have a series of mysql queries to allow users to set filters for the data that is returned. They are searching for clients (Site_ID) with projects (Request_ID). A single client can have multiple projects. I want to be able to count the number of projects that are returned from a query. Here is the tail end of that code...

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved