Select query locks tables in Innodb

2009-03-03 Thread Carl
are attempting to enter transactions to wait until the select query is finished. The query is sizable so I have not included it here (I can if that would be helpful.) Explain shows (abbreviated): id select_typetabletypepossible keys key_len

Re: Select query locks tables in Innodb

2009-03-03 Thread Brent Baisley
A SELECT will/can lock a table. It almost always does in MyISAM (no insert/updates), almost never does in InnoDB. There is an exception to every rule. The problem is most likely in the 107488 rows part of the query. That's too many rows for InnoDB to keep a version history on so it's likely just

Re: Select query locks tables in Innodb

2009-03-03 Thread Perrin Harkins
On Tue, Mar 3, 2009 at 10:53 AM, Carl c...@etrak-plus.com wrote: A query that is selecting data for a report locks the files that it accesses forcing users who are attempting to enter transactions to wait until the select query is finished. Is it an INSERT INTO...SELECT FROM? Those lock

Re: Select query locks tables in Innodb

2009-03-03 Thread Baron Schwartz
On Tue, Mar 3, 2009 at 12:35 PM, Brent Baisley brentt...@gmail.com wrote: A SELECT will/can lock a table. It almost always does in MyISAM (no insert/updates), almost never does in InnoDB. There is an exception to every rule. The problem is most likely in the 107488 rows part of the query

HOW TO QUERY(SELECT) and display MULTIPLE AUTHORS

2009-02-22 Thread PJ
SELECT b.title, b.sub_title, b.descr, b.comment, b.bk_cover, b.copyright, b.ISBN, c.publisher, CONCAT_WS(' ', first_name, last_name) AS Author FROM book AS b LEFT JOIN book_author AS ab ON b.id = ab.bookID LEFT JOIN author AS a ON ab.authID=a.id LEFT JOIN book_publisher AS abc ON b.id

Re: Select data from another Mysql Server?

2009-02-13 Thread Baron Schwartz
Hello, On Thu, Feb 12, 2009 at 11:54 PM, Kiran Waje kiranw...@gmail.com wrote: I have two Mysql servers and I want to Read data from one Mysql server to another using stored procedure. You may be able to use the Federated engine. Check the output of SHOW ENGINES. -- Baron Schwartz,

Select data from another Mysql Server?

2009-02-12 Thread Kiran Waje
I have two Mysql servers and I want to Read data from one Mysql server to another using stored procedure.

Help with SELECT and possible JOIN

2009-01-19 Thread Duane Hill
)) ) ENGINE=MyISAM; I need to select all tga_body_blob.blob_data where tga_body.blob_id is equal to tga_body_blob.blob_id and tga_body.file_id is equal to 'some_name' ordered by tga_body.blob_pos. I can type in english what I want. However, I am stumped on the select statement. I'm

Re: Help with SELECT and possible JOIN

2009-01-19 Thread Duane Hill
`blob_data` (`blob_data`(64)) ) ENGINE=MyISAM; I need to select all tga_body_blob.blob_data where tga_body.blob_id is equal to tga_body_blob.blob_id and tga_body.file_id is equal to 'some_name' ordered by tga_body.blob_pos. I can type in english what I want. However, I am stumped on the select

Can't get expected SELECT GROUP BY results

2008-12-26 Thread Fish Kungfu
:30| |yard|cat|109.83472, 22.45278, 43.29317| 2008-12-2601:14:30| |yard|dog|110.05429, 22.43897, 43.31427| 2008-12-2601:14:57| * What I want to do is SELECT

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Peter Brawley
What I want to do is SELECT only the most recent dateTime and critterXYZ for each critterName and return one row for each unique critterName. For examples discussion see Within-group aggregates at http://localhost/artful/infotree/queries.php. PB - Fish Kungfu wrote: I have a dataset

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Peter Brawley
Sorry LOL, make that http://www.artfulsoftware.com/infotree/queries.php. PB - Peter Brawley wrote: What I want to do is SELECT only the most recent dateTime and critterXYZ for each critterName and return one row for each unique critterName. For examples discussion see Within-group

Re: Can't get expected SELECT GROUP BY results

2008-12-26 Thread Fish Kungfu
Thank you, Peter! I'll give that a try. ~~Fish~~ On Fri, Dec 26, 2008 at 2:33 PM, Peter Brawley peter.braw...@earthlink.netwrote: Sorry LOL, make that http://www.artfulsoftware.com/infotree/queries.php. PB - Peter Brawley wrote: What I want to do is SELECT only the most recent

select

2008-12-18 Thread Marcos Dutra
Hi all, I would like how to function select working internals. If each select in BD is mono process or various select is processes in same time without lock table? Tks Marcos -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http

SELECT with replacement chars

2008-12-05 Thread spacemarc
Hi how can i replace, in a SELECT query, the last 3 numbers with asterisks? from 0123456789 to 0123456*** -- Scripts: http://www.spacemarc.it -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]

RE: SELECT with replacement chars

2008-12-05 Thread Weston, Craig (OFT)
Hi how can i replace, in a SELECT query, the last 3 numbers with asterisks? from 0123456789 to 0123456*** My psudocode for this would be something like: Select CONCAT(left$(`field`,(LENGTH(a)-3),'***') From `table` But there might be more efficient ideas out

RE: SELECT with replacement chars

2008-12-05 Thread Jerry Schwartz
-Original Message- From: spacemarc [mailto:[EMAIL PROTECTED] Sent: Friday, December 05, 2008 8:50 AM To: MySQL Subject: SELECT with replacement chars Hi how can i replace, in a SELECT query, the last 3 numbers with asterisks? from 0123456789 to 0123456*** [JS] SELECT CONCAT(LEFT

Re: SELECT with replacement chars

2008-12-05 Thread spacemarc
thanks, it works fine (on mysql 4 and 5) SELECT CONCAT(LEFT(myfield,LENGTH(myfield) - 3), '***') FROM table; -- Scripts: http://www.spacemarc.it -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]

Re: Query to Select records in the last 4 weeks

2008-12-04 Thread sangprabv
Hi, I have tried to use this query: SELECT count(smsc_id) as total, insertdate FROM momtbak WHERE insertdate BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 4 WEEK) AND CURRENT_DATE() group by week(date_format(insertdate,'%Y-%m-%d'),3) to group records in the last 4 weeks by week. But the result

[SOLVED]Re: Query to Select records in the last 4 weeks

2008-12-04 Thread sangprabv
Hi, I finally found the solution SELECT count( smsc_id ) AS total, week( insertdate ) AS tanggal FROM momtbak WHERE insertdate BETWEEN DATE_SUB( CURRENT_DATE( ) , INTERVAL 4 WEEK ) AND CURRENT_DATE( ) GROUP BY week( insertdate ) Willy -- MySQL General Mailing List For list archives: http

Query to Select records in the last 4 weeks

2008-12-03 Thread sangprabv
Hi, I get stuck to build a query to select records between curdate() and the last 4 weeks and groupped by week. I tested with: SELECT * FROM momtbak WHERE insertdate BETWEEN curdate( ) AND curdate( ) - INTERVAL 4 week It doesn't work. Please help, TIA. Willy Every why hath a wherefore

Re: Query to Select records in the last 4 weeks

2008-12-03 Thread Daevid Vincent
On Thu, 2008-12-04 at 08:27 +0700, sangprabv wrote: Hi, I get stuck to build a query to select records between curdate() and the last 4 weeks and groupped by week. I tested with: SELECT * FROM momtbak WHERE insertdate BETWEEN curdate( ) AND curdate( ) - INTERVAL 4 week It doesn't

Re: Query to Select records in the last 4 weeks

2008-12-03 Thread sangprabv
: sangprabv [EMAIL PROTECTED] Subject: Re: Query to Select records in the last 4 weeks Date: Wed, 03 Dec 2008 17:52:32 -0800 SELECT * FROM momtbak WHERE insertdate BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 4 WEEK) AND CURRENT_DATE(); -- MySQL General Mailing List For list archives: http

Re: SELECT locking tables.... in other databases

2008-11-27 Thread Ananda Kumar
] wrote: Hi list.We have 2 tables, both have a few inserts, many updates and the occasional select. When running a select joining the 2 tables (which can take upto 20 seconds to complete, they are large tables) all updates are blocked and the maxconnections is quickly reached. We tried

Re: SELECT locking tables.... in other databases

2008-11-27 Thread David Scott
STATUS, which will give complete activity on innodb engine, including lock information. Please show use the output of these. regards anandkl On 11/27/08, David Scott [EMAIL PROTECTED] wrote: Hi list.We have 2 tables, both have a few inserts, many updates and the occasional select. When

Re: SELECT locking tables.... in other databases

2008-11-27 Thread Pradeep Chandru
Hi David, can you please let me know what is the select query and the update query along with the explain plan of the same. can you please let me know if you are using innodb storage engine? Regards, Chandru www.mafiree.com On Thu, Nov 27, 2008 at 4:45 PM, David Scott [EMAIL PROTECTED]wrote

SELECT locking tables.... in other databases

2008-11-27 Thread David Scott
Hi list.We have 2 tables, both have a few inserts, many updates and the occasional select. When running a select joining the 2 tables (which can take upto 20 seconds to complete, they are large tables) all updates are blocked and the maxconnections is quickly reached. We tried copying the data

Re: SELECT locking tables.... in other databases

2008-11-27 Thread David Scott
, sorry, here it is: SELECT gS.gameid, g.gamename, COUNT(DISTINCT(gS.sessionid)) 'sessions', SUM(gSL.endTime - gSL.startTime)/COUNT(DISTINCT(gS.sessionid))/60 'average SESSION time', SUM(gSL.totalTime)/COUNT(DISTINCT(gS.sessionid))/60 'average PLAY time', SUM(gSL.totalTime)/60 FROM

Optimizing query question, EXPLAIN SELECT ...

2008-11-25 Thread Thomas Thomas
Hi, I am pretty new in optimizing tables with index and may need some help. This is my query: EXPLAIN SELECT timestamp FROM Meting_INT_COPY WHERE blockid = '200811252000' ORDER BY timestamp DESC LIMIT 1 If I have an index(blockid), EXPLAIN will return the following information: type

SELECT through many databases

2008-11-21 Thread Andre Matos
Hello, Let's suppose I have 5 database: db1, db2, db3, db4, and db5. They all have the same structure but different data. I would like perform this select SELECT TaskDoneOn, TaskDoneBy FROM {database} WHERE TaskDoneOn IS NOT NULL and collect the data from all 5 database. However, I would

Re: SELECT through many databases

2008-11-21 Thread Peter Brawley
structure but different data. I would like perform this select SELECT TaskDoneOn, TaskDoneBy FROM {database} WHERE TaskDoneOn IS NOT NULL and collect the data from all 5 database. However, I would like to avoid doing something like this: SELECT TaskDoneOn, TaskDoneBy FROM db1 WHERE TaskDoneOn

Re: SELECT through many databases

2008-11-21 Thread Brent Baisley
On Fri, Nov 21, 2008 at 12:44 PM, Andre Matos [EMAIL PROTECTED] wrote: Hello, Let's suppose I have 5 database: db1, db2, db3, db4, and db5. They all have the same structure but different data. I would like perform this select SELECT TaskDoneOn, TaskDoneBy FROM {database} WHERE TaskDoneOn

Re: SELECT through many databases

2008-11-21 Thread Andre Matos
I was trying to avoid both since the SELECT statement is not fixed. Time to time, users want different information. Thanks, Andre On 21-Nov-08, at 12:59 PM, Peter Brawley wrote: Andre Matos wrote: Today I have 5, but tomorrow I can have 50 and I don't want to forget any database. Do

Re: SELECT through many databases

2008-11-21 Thread Andre Matos
Sounds interesting, but does the MERGER support complex SELECT statements and LEFT JOIN? Andre On 21-Nov-08, at 1:45 PM, Brent Baisley wrote: On Fri, Nov 21, 2008 at 12:44 PM, Andre Matos [EMAIL PROTECTED] wrote: Hello, Let's suppose I have 5 database: db1, db2, db3, db4, and db5

Re: SELECT through many databases

2008-11-21 Thread Brent Baisley
, Nov 21, 2008 at 2:12 PM, Andre Matos [EMAIL PROTECTED] wrote: Sounds interesting, but does the MERGER support complex SELECT statements and LEFT JOIN? Andre On 21-Nov-08, at 1:45 PM, Brent Baisley wrote: On Fri, Nov 21, 2008 at 12:44 PM, Andre Matos [EMAIL PROTECTED] wrote: Hello

RE: SELECT through many databases

2008-11-21 Thread Jerry Schwartz
Many MySQL APIs (such as PHP) allow you to treat the result returned from a SHOW statement as you would a result set from a SELECT; see Chapter 22, APIs and Libraries, or your API documentation for more information. In addition, you can work in SQL with results from queries on tables

Re: SELECT through many databases

2008-11-21 Thread Andre Matos
to treat the result returned from a SHOW statement as you would a result set from a SELECT; see Chapter 22, APIs and Libraries, or your API documentation for more information. In addition, you can work in SQL with results from queries on tables in the INFORMATION_SCHEMA database, which you

Re: SELECT through many databases

2008-11-21 Thread Olexandr Melnyk
: Many MySQL APIs (such as PHP) allow you to treat the result returned from a SHOW statement as you would a result set from a SELECT; see Chapter 22, APIs and Libraries, or your API documentation for more information. In addition, you can work in SQL with results from queries on tables

Re: SELECT through many databases

2008-11-21 Thread Olexandr Melnyk
in the list. I am not allowed to. That's why I was thinking to use only a SELECT statement to do the job as I have been doing. Thanks, Andre On 21-Nov-08, at 3:16 PM, Olexandr Melnyk wrote: Hello Andre, I would recommend you to rethink your criteria (if there's any) for splitting

Re: SELECT through many databases

2008-11-21 Thread Claudio Nanni
the only way to proceed, remaining on mysql environment, is to use metadata, that is information_schema. for instance the following statement gives you all the tables in your mysql instance: mysql select TABLE_SCHEMA,TABLE_NAME from information_schema.TABLES where TABLE_NAME='your_table

Re: SELECT through many databases

2008-11-21 Thread Andre Matos
as suggested here in the list. I am not allowed to. That's why I was thinking to use only a SELECT statement to do the job as I have been doing. Thanks, Andre On 21-Nov-08, at 3:16 PM, Olexandr Melnyk wrote: Hello Andre, I would recommend you to rethink your criteria (if there's any

RE: SELECT through many databases

2008-11-21 Thread Martin Gainty
:21:39 -0500 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: SELECT through many databases CC: mysql@lists.mysql.com A MERGE table is just a virtual table that is made up of other tables. You treat it no differently than any other table, pretend it's a real table. You could

select into outfile php problem

2008-10-21 Thread kalin m
hi all... i have a strange problem with a simple script that is doing select into outfile... the thing just does that. it does a select into an outfile. if i print the query that's passed to mysql_result in the script and then copy it and paste it z`into the mysql client it works fine

Re: select ... into outfile=stdout ?

2008-10-20 Thread Moon's Father
Maybe you can use mysql -e instead. On Mon, Oct 20, 2008 at 12:51 AM, walter harms [EMAIL PROTECTED] wrote: hi ronaldo i tried and failed. it seems that mysql has no option to specify a select statement. did i mis something ? re, wh walter harms schrieb: hi ronaldo, iadmit i

Re: SQL select basics

2008-10-20 Thread Moon's Father
select * from ( SELECT ID_number, count( CU_number ) AS CC FROM MyTable GROUP BY ID_number ) T WHERE CC = ( select max(cc) from ( SELECT ID_number, count( CU_number ) AS CC FROM MyTable GROUP BY ID_number ) T2 ) On Wed, Oct 15, 2008 at 5:08 PM, dave aptiva [EMAIL PROTECTED]wrote: Hello all

Re: select ... into outfile=stdout ?

2008-10-19 Thread walter harms
- From: walter harms [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2008 5:06 AM To: 'mysql' Subject: select ... into outfile=stdout ? hi list, i need some options from outfile (exspecialy:FIELDS TERMINATED BY) and would like to send the output to stdout to further processing

Re: select ... into outfile=stdout ?

2008-10-19 Thread walter harms
hi ronaldo i tried and failed. it seems that mysql has no option to specify a select statement. did i mis something ? re, wh walter harms schrieb: hi ronaldo, iadmit i was mysql (the command) fixated :) thx a lot, wh Rolando Edwards schrieb: Try mysqldump !!! On this web page

SQL select basics

2008-10-17 Thread dave aptiva
Hello all, I'm new to sql and have a question if someone would be kind enough to help me with, if I have a table that stores telemarketers by ID_number and the customer that they spoke to by CU_number and I use a select statement such as; SELECT ID_number, count( CU_number ) FROM MyTable

Re: SQL select basics

2008-10-17 Thread Ian Christian
2008/10/17 dave aptiva [EMAIL PROTECTED]: I tried SELECT ID_number, max( count( CU_number ) ) but this causes an error # - Invalid use of group function # sqlite3 SQLite version 3.5.9 Enter .help for instructions sqlite create table moo (id_number, cu_number); sqlite insert into moo(1, 1

SQL select basics

2008-10-17 Thread dave aptiva
Hello all, I'm new to sql and have a question if someone would be kind enough to help me with, if I have a table that stores telemarketers by ID_number and the customer that they spoke to by CU_number and I use a select statement such as; SELECT ID_number, count( CU_number ) FROM MyTable

Re: SQL select basics

2008-10-17 Thread Jim Lyons
SELECT ID_number, count( CU_number ) FROM MyTable GROUP BY ID_number order by 2 desc limit 10 will give you the top 10. Change 10 to whatever you want or take off the limit clause to get all records. On Fri, Oct 17, 2008 at 4:25 AM, dave aptiva [EMAIL PROTECTED]wrote: Hello all, I'm new

select ... into outfile=stdout ?

2008-10-16 Thread walter harms
hi list, i need some options from outfile (exspecialy:FIELDS TERMINATED BY) and would like to send the output to stdout to further processing. unfortunately i found no proper way to force the output to stdout. for now i use the redirection of the mysql -NB output but the interface lacks the

RE: select ... into outfile=stdout ?

2008-10-16 Thread Rolando Edwards
meaning as the corresponding clauses for LOAD DATA INFILE. See Section 12.2.6, LOAD DATA INFILE Syntax. By default, its output to stdout. Give it a try !!! -Original Message- From: walter harms [mailto:[EMAIL PROTECTED] Sent: Thursday, October 16, 2008 5:06 AM To: 'mysql' Subject: select

Re[4]: SELECT DISTINCT with ORDER BY implementation

2008-09-30 Thread Michael Widenius
Hi! Andrew == Andrew Aksyonoff [EMAIL PROTECTED] writes: Andrew Hello Sergey, Andrew Monday, September 15, 2008, 10:41:31 PM, you wrote: in MySQL but in general case it can't assume any order and will have to re-sort the sub-select result by outer GROUP BY instead of inner ORDER

Re[5]: SELECT DISTINCT with ORDER BY implementation

2008-09-30 Thread Andrew Aksyonoff
Hello Michael, Tuesday, September 30, 2008, 8:00:36 PM, you wrote: Andrew However if the specific sorting algorithm is not stable it *might* MW It's not stable; MySQL is using several different technics to MW calculate GROUP BY and may thus return the rows in any order within MW the group by.

long select query result as as query string on another select statment

2008-09-26 Thread Madan Thapa
Hi, - (SELECT id FROM domains where name='abc.com'); gives a result of 124 i am also able to use and get proper results for the following query: select * from domains where id=(SELECT id FROM domains where name='abc.com

Re: long select query result as as query string on another select statment

2008-09-26 Thread Ananda Kumar
what is the issue ur facing. Any syntax error or something else. trying usin IN instead of = On 9/26/08, Madan Thapa [EMAIL PROTECTED] wrote: Hi, - (SELECT id FROM domains where name='abc.com'); gives a result of 124 i am also able

Re: long select query result as as query string on another select statment

2008-09-26 Thread Madan Thapa
-- --- (SELECT id FROM domains where name='abc.com'); gives a result of 124 i am also able to use and get proper results for the following query: select * from domains where id=(SELECT id FROM domains where name='abc.com

Re: long select query result as as query string on another select statment

2008-09-26 Thread Madan Thapa
Hi, ok i got it working. it was a typo(lol), i missed from in the initial select statment Wrong ### select * db_users where db_id=(SELECT id FROM data_bases where dom_id=(SELECT id FROM domains where name='abc.com')); Correct ## select * from db_users where db_id=(SELECT

Re: mysql big table select speed

2008-09-25 Thread Carles Pina i Estany
Hello, On Sep/24/2008, Phil wrote: Just a wild guess but, did you perhaps change the filesystem to a journalling filsystem when moving to the different server? mount reports the same (ext3) I once accidently moved my database from an ext2 to an ext3 partition and it took me a while to

Re: mysql big table select speed

2008-09-25 Thread Ananda Kumar
does it have the same network speed as your old server. On 9/25/08, Carles Pina i Estany [EMAIL PROTECTED] wrote: Hello, On Sep/24/2008, Phil wrote: Just a wild guess but, did you perhaps change the filesystem to a journalling filsystem when moving to the different server? mount

Re: mysql big table select speed

2008-09-25 Thread Ananda Kumar
is /tmpdir parameter on both machines using the default value On 9/25/08, Carles Pina i Estany [EMAIL PROTECTED] wrote: Hello, On Sep/25/2008, Ananda Kumar wrote: does it have the same network speed as your old server. yes, it has. But I'm running the query from localhost :-) (socket

Re: mysql big table select speed

2008-09-25 Thread Carles Pina i Estany
Hello, On Sep/25/2008, Ananda Kumar wrote: is /tmpdir parameter on both machines using the default value Old machine: yes. New machine: I have tried two places (different partitions, same FS -ext3-, same hard disk). On the old machine it's in a different partition of the same hard disk than

Re: mysql big table select speed

2008-09-25 Thread Carles Pina i Estany
Hello, On Sep/25/2008, Ananda Kumar wrote: does it have the same network speed as your old server. yes, it has. But I'm running the query from localhost :-) (socket connection). Even, the query only returns one number and I don't have any federated tables, etc. On 9/25/08, Carles Pina i

Re: mysql big table select speed

2008-09-25 Thread Ananda Kumar
On the new machine its on a different partition than the database. Also did u try to analyze the table and run the query On 9/25/08, Carles Pina i Estany [EMAIL PROTECTED] wrote: Hello, On Sep/25/2008, Ananda Kumar wrote: is /tmpdir parameter on both machines using the default value

Re: mysql big table select speed

2008-09-25 Thread Carles Pina i Estany
Hello, On Sep/25/2008, Ananda Kumar wrote: On the new machine its on a different partition than the database. Also did u try to analyze the table and run the query I will do it (maybe on Saturday, as I guess that will take long time to do it). But I think that I did last weekend when I

mysql big table select speed

2008-09-24 Thread Carles Pina i Estany
hardware are quite similar, and servers software installation are similar too (Debian, ext3). Mysql version: mysql select version(); +--+ | version()| +--+ | 5.0.32-Debian_7etch6-log | +--+ 1 row in set (0.00 sec

Re: mysql big table select speed

2008-09-24 Thread Phil
seconds the query that I will show to 2 min. 50 seconds). Servers hardware are quite similar, and servers software installation are similar too (Debian, ext3). Mysql version: mysql select version(); +--+ | version()| +--+ | 5.0.32

Complex SELECT

2008-09-22 Thread Andre Matos
Hello, I need help with a SQL Select statement: I have three tables: report, category, and optional a) report table has 3 fields: ReportId, CategoryId, ReportDesc b) category table has 2 fields: CategoryId, CategoryDesc c) optional table has three fields: OptionalId, CategoryId

Re: Complex SELECT

2008-09-22 Thread Jim Lyons
look at using the group_concat function on OptionalDesc and group by the other fields. On Mon, Sep 22, 2008 at 1:40 PM, Andre Matos [EMAIL PROTECTED]wrote: Hello, I need help with a SQL Select statement: I have three tables: report, category, and optional a) report table has 3 fields

Re: Complex SELECT

2008-09-22 Thread Andre Matos
Select statement: I have three tables: report, category, and optional a) report table has 3 fields: ReportId, CategoryId, ReportDesc b) category table has 2 fields: CategoryId, CategoryDesc c) optional table has three fields: OptionalId, CategoryId, OptionalDesc I would like to have something

Re: Wierd INSERT ... SELECT syntax problem

2008-09-06 Thread Brent Baisley
Well, for your simple example, you can use query variables to add the counters. SET @cntr:=0, @lastVal:='A' INSERT INTO tableB LOC,DATA SELECT CONCAT(LOC, CONCAT( IF(@lastVal=LOC, @cntr:[EMAIL PROTECTED], @cntr:=0), IF(@lastVal:=LOC,'',''))) LOC, CONCAT(DATA, @cntr) FROM tableA ORDER

Re: Wierd INSERT ... SELECT syntax problem

2008-09-06 Thread Dan Tappin
:='A' INSERT INTO tableB LOC,DATA SELECT CONCAT(LOC, CONCAT( IF(@lastVal=LOC, @cntr:[EMAIL PROTECTED], @cntr:=0), IF(@lastVal:=LOC,'',''))) LOC, CONCAT(DATA, @cntr) FROM tableA ORDER BY LOC That should add a sequential number to LOC and DATA that will reset to 0 whenever the value of LOC

Wierd INSERT ... SELECT syntax problem

2008-09-05 Thread Dan Tappin
I have an existing data set - here is an example (the real one is more complex than this) LOC DATA - A 1 B 2 C 3 D 4 E 5 F 6 ... and I am looking to run some sort of INSERT ... SELECT on this to make a new table like this: LOC

Complex conditional statement during select

2008-08-28 Thread Jay Blanchard
SELECT this, that, theOther, SUM(IF(SUBSTRING(myDate,1,10) = '20080101' AND SUBSTRING(myDate,1,10) = '20080131'), 1, 0) AS `January` FROM theTable GROUP BY theOther Throws this error... ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Re: Complex conditional statement during select

2008-08-28 Thread DuĊĦan Pavlica
Try this: SELECT this, that, theOther, SUM(IF(SUBSTRING(myDate,1,10) = '20080101' AND SUBSTRING(myDate,1,10) = '20080131', 1, 0)) AS `January` FROM theTable GROUP BY theOther Problem was in parentheses Dusan Jay Blanchard napsal(a): SELECT this, that, theOther, SUM(IF(SUBSTRING(myDate,1,10

SELECT in NULL state for a long time

2008-08-14 Thread Vlad Shalnev
Hi, OS - Solaris 10, 32 Gb RAM, mysql 64-bit 4.1.22 Every day I see in processlist many SELECT queries that stay in NULL state for a long time. Something Like this | 368966 | radius | fire-u1:35671 | srg_conf | Query | 106 | NULL |SELECT id, deleted_id, status, name

Re: SELECT in NULL state for a long time

2008-08-14 Thread Krishna Chandra Prajapati
64-bit 4.1.22 Every day I see in processlist many SELECT queries that stay in NULL state for a long time. Something Like this | 368966 | radius | fire-u1:35671 | srg_conf | Query | 106 | NULL |SELECT id, deleted_id, status, name, LEFT( value, 1000 ) FROM s | 368967

RE: SELECT in NULL state for a long time

2008-08-14 Thread Martin Gainty
If you want MYSQL to process the SELECT, including information about how tables are joined and in which order usehttp://dev.mysql.com/doc/refman/5.0/en/using-explain.htmle.g. EXPLAIN [EXTENDED] SELECT select_optionsIf you want MySQL uses the stored key distribution to decide the order

SELECT [n] nested sets

2008-08-12 Thread John Smith
, PRIMARY KEY (`id`), KEY `root_id` (`root_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=21 ; I can select all trees and order them by the date-field of their root. SELECT n.*, count(*)+(n.lft1) AS level FROM posts n, posts p WHERE n.lft BETWEEN p.lft AND p.rgt

Re: SELECT N records from each category

2008-08-11 Thread Kevin Waterson
This one time, at band camp, Perrin Harkins [EMAIL PROTECTED] wrote: In your case, you might be able to just cheat it with some MySQL-specific LIMIT stuff: Thanks very much Perrin, this is most useful and I can take it from here. Kind regards Kevin -- MySQL General Mailing List For list

SELECT N records from each category

2008-08-10 Thread Kevin Waterson
I have 3 tables (schema below) with categories, questions and answers. Each category can of course have many questions in it. Also, the answers are multiple choice, so each question can have several related answers. I am trying to achieve 2 goals. 1) SELECT N questions and the related answers

Re: SELECT N records from each category

2008-08-10 Thread Peter Brawley
1) SELECT N questions and the related answers from each category. See Within-group quotas (Top N per group) at http://www.artfulsoftware.com/infotree/queries.php. PB Kevin Waterson wrote: I have 3 tables (schema below) with categories, questions and answers. Each category can of course

Re: SELECT N records from each category

2008-08-10 Thread Kevin Waterson
This one time, at band camp, Peter Brawley [EMAIL PROTECTED] wrote: See Within-group quotas (Top N per group) at http://www.artfulsoftware.com/infotree/queries.php. Yes, I have seen that, very clever. How does it relate to my situation? Simply point to vague references is not helpful. Kevin

Re: SELECT N records from each category

2008-08-10 Thread Peter Brawley
How does it relate to my situation? Simply point to vague references is not helpful. Vague? Not in the slightest. General? Indeed, by design. You'd written Any help in this matter hugely appreciated. If that's not so, please feel free entirely ignore my suggestion. PB - Kevin Waterson

Re: SELECT N records from each category

2008-08-10 Thread Kevin Waterson
This one time, at band camp, Peter Brawley [EMAIL PROTECTED] wrote: Vague? Not in the slightest. General? Indeed, by design. I have read this before.. It uses a single table, I am using multiple tables. I am not selecting the TOP 10 or whatever. This example has no relationships where the

Re: SELECT N records from each category

2008-08-10 Thread Peter Brawley
It uses a single table, I am using multiple tables. I am not selecting the TOP 10 or whatever. This example has no relationships where the schema I presented does. Eh? We can treat any query as one derived table; it makes no difference to the principle involved. And the same within-aggregate

Re: SELECT N records from each category

2008-08-10 Thread Perrin Harkins
trying to achieve 2 goals. 1) SELECT N questions and the related answers from each category. The result needs to have say, 5 questions from each category. Of course, the answers for each of the questions needs to be there also. 2) SELECT N questions and related answers from specified

Re: COUNT returned rows of a SELECT

2008-07-31 Thread Rob Wultsch
On Wed, Jul 30, 2008 at 9:41 PM, Fish Kungfu [EMAIL PROTECTED] wrote: Using MySQL commands only (not PHP's mysql_num_rows), is there a way to COUNT the number of rows returned from a SELECT.GROUP BY? My primary SELECT query is this: SELECT aviName,MAX(dateTime) FROM aviTrackerMain WHERE

Re: COUNT returned rows of a SELECT

2008-07-31 Thread Fish Kungfu
Thanks for trying guys, but that's still not quite what I'm looking for. All I really want is the total number of rows returned for the query result. For example, my the SELECT that Ananda suggested returns this: mysql SELECT aviName,MAX(dateTime) ,count(*) FROM aviTrackerMain WHERE DATE

RE: COUNT returned rows of a SELECT

2008-07-31 Thread Jerry Schwartz
-Original Message- From: Fish Kungfu [mailto:[EMAIL PROTECTED] Sent: Thursday, July 31, 2008 12:41 AM To: mysql@lists.mysql.com Subject: COUNT returned rows of a SELECT Using MySQL commands only (not PHP's mysql_num_rows), is there a way to COUNT the number of rows returned from a SELECT

Re: COUNT returned rows of a SELECT

2008-07-31 Thread Perrin Harkins
On Thu, Jul 31, 2008 at 8:00 AM, Fish Kungfu [EMAIL PROTECTED] wrote: Ideally, I was hoping COUNT() could work like this, BUT it doesn't of course: mysql SELECT COUNT(SELECT aviName,MAX(dateTime) ,count(*) FROM aviTrackerMain WHERE DATE(dateTime) LIKE CONCAT(DATE(NOW()),'%') GROUP BY aviName

Re: COUNT returned rows of a SELECT

2008-07-31 Thread Fish Kungfu
Beautiful! That's exactly what I needed. Thanks, Roy mysql SELECT COUNT(*) FROM (SELECT aviName,MAX(dateTime) FROM aviTrackerMain WHERE DATE(dateTime) LIKE CONCAT(DATE(NOW()),'%') GROUP BY aviName) as T; +--+ | COUNT(*) | +--+ | 49 | +--+ 1 row in set (0.30 sec

COUNT returned rows of a SELECT

2008-07-30 Thread Fish Kungfu
Using MySQL commands only (not PHP's mysql_num_rows), is there a way to COUNT the number of rows returned from a SELECT.GROUP BY? My primary SELECT query is this: SELECT aviName,MAX(dateTime) FROM aviTrackerMain WHERE DATE(dateTime) LIKE CONCAT(DATE(NOW()),'%') GROUP BY aviName

Re: COUNT returned rows of a SELECT

2008-07-30 Thread Ananda Kumar
SELECT aviName,MAX(dateTime) ,count(*) FROM aviTrackerMain WHERE DATE(dateTime) LIKE CONCAT(DATE(NOW()),'%') GROUP BY aviName; This will also give you count of rows On 7/31/08, Fish Kungfu [EMAIL PROTECTED] wrote: Using MySQL commands only (not PHP's mysql_num_rows), is there a way

How do I (can I) use aggregate functions inside a select

2008-07-25 Thread David Ruggles
I may be approaching this all wrong, but I need to know a percentage of total sales within a select statement. So I can do something like this: Select company, state, sales, sum(sales) / sales as percent From Sales Thanks, David Ruggles CCNA MCSE (NT) CNA A+ Network EngineerSafe Data

Re: How do I (can I) use aggregate functions inside a select

2008-07-25 Thread Ananda Kumar
yes, u can use the below sql. regards anandkl On 7/25/08, David Ruggles [EMAIL PROTECTED] wrote: I may be approaching this all wrong, but I need to know a percentage of total sales within a select statement. So I can do something like this: Select company, state, sales, sum(sales) / sales

RE: How do I (can I) use aggregate functions inside a select

2008-07-25 Thread David Ruggles
: Ananda Kumar [mailto:[EMAIL PROTECTED] Sent: Friday, July 25, 2008 10:37 AM To: David Ruggles Cc: mysql Subject: Re: How do I (can I) use aggregate functions inside a select yes, u can use the below sql. regards anandkl On 7/25/08, David Ruggles [EMAIL PROTECTED] wrote: I may be approaching

Re: How do I (can I) use aggregate functions inside a select

2008-07-25 Thread walter harms
David Ruggles wrote: I may be approaching this all wrong, but I need to know a percentage of total sales within a select statement. So I can do something like this: Select company, state, sales, sum(sales) / sales as percent From Sales mmh, you want sum(sales where company=foo

RE: How do I (can I) use aggregate functions inside a select

2008-07-25 Thread Ian Simpson
Hi David, Try Select company, state, sales, sum(sales) / sales as percent From Sales GROUP BY company, state; Not sure if you always want to group by state; if each company exists in only one state then the group by is irrelevant, if not then it will give you the by-state breakdown. On Fri

<    1   2   3   4   5   6   7   8   9   10   >