RE: sql help: delete row where only related to one other row

2008-02-21 Thread roger.maynard
Take a look at http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.ht ml CASCADE: Delete or update the row from the parent table and automatically delete or update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between two

Re: SQL help/problem with timestamped data differences

2008-01-08 Thread Dan Buettner
Mark, is the 'secs' column the offset from the minimum value of the timestamp column? If so, you might try something like this: SELECT UNIX_TIMESTAMP(MIN(timestamp)) INTO @min_timestamp FROM my_table; SELECT uid, timestamp, UNIX_TIMESTAMP(timestamp) - @min_timestamp AS secs FROM my_table ORDER

Re: SQL help for qty Sold YTD...

2005-11-04 Thread Rhino
I spent several minutes looking at your question and your data model and nothing jumped out at me that precluded you from determining the quantity of the this vendor's items sold via this data model. I might have missed something though. I'm a little concerned that your LineItem table appeared to

Re: SQL help for qty Sold YTD...

2005-11-04 Thread SGreen
I would first try refactoring your SQL to use INNER JOIN statements instead of the comma separated lists you are currently using. I would also not use any subqueries. Test this and see if it works for you: SELECT SUM(li.quantity) as qtysoldytd FROM LineItem li INNER JOIN Sales sa on

Re: SQL help: Updating Strange Chrs.

2005-09-22 Thread Daniel Kasak
m i l e s wrote: Hi, I have an odd situation where I was handed just bad data, and while I have cleaned it up to the best of my ability one hurdle remains. I have a situation where I have the following example in a field: Canna ÒBengalÒ. Note the odd chrs Ò in the field ? I need to

RE: SQL help

2005-08-23 Thread Jay Blanchard
[snip] Unfortunately the item field has got data with quotes around it. IE KP-00310. I need to clean up the data and have the field contain just KP-00310. Since I have 10,000 records, I need a update statement or something to clean that up. Any ideas ? [/snip]

Re: SQL help

2005-08-23 Thread Peter Brawley
Darryl, Unfortunately the item field has got data with quotes around it. IE "KP-00310". I need to clean up the data and have the field contain just KP-00310. Since I have 10,000 records, I need a update statement or something to clean that up. To remove all double quotes: UPDATE tablename

Re: SQL help

2005-06-26 Thread Jochem van Dieten
On 6/26/05, 2wsxdr5 wrote: Can someone tell me why this query works... SELECT UserKey FROM( SELECT UserKey, Count(GiftKey) Gifts FROM Gift Group BY UserKey ) GC WHERE GC.Gifts = 3 Why this construction and not simply: SELECT UserKey FROM Gift GROUP BY UserKey HAVING Count(GiftKey) =

RE: SQL help

2005-02-28 Thread Rob Brooks
correction in question below, the problem is not in record '7047' but in the record which starts with the name 'Triad' also ... I'm using 4.0.20-standard-log -Original Message- From: Rob Brooks [mailto:[EMAIL PROTECTED] Sent: Monday, February 28, 2005 2:56 PM To: mysql@lists.mysql.com

RE: SQL help

2005-02-28 Thread Michael Dykman
Properly, NULL values should be matched with 'foo IS NULL', as opposed to 'foo = NULL' which, by standard definition, always returns false regardless of the value of foo - michael dykman On Mon, 2005-02-28 at 16:02, Rob Brooks wrote: correction in question below, the problem is not in record

Re: SQL help

2005-02-28 Thread Michael Stassen
NULL is an unknown value. Consequently, you cannot compare NULLs the way you expect. Effectively, = NULL is always false. Instead of items_online.ID = NULL you have to use items_online.ID IS NULL Michael Rob Brooks wrote: correction in question below, the problem is not in record '7047'

Re: SQL help

2005-02-28 Thread Harald Fuchs
In article [EMAIL PROTECTED], Rob Brooks [EMAIL PROTECTED] writes: The only difference in the 2 statements is the 'where items_online.ID = NULL' part. Clearly in the first set, items_online.ID = NULL in record 7047 ... Nope. items_online.ID IS NULL for that record, but comparing anything =

Re: SQL help

2004-06-03 Thread Michael Stassen
Bob Lockie wrote: What I really want was mysql update records set records.prio=2 where records.in=(select records.id from records, audit_log, audit_log_records where audit_log.tracker_id=audit_log_records.tracker_id and records.id=audit_log_records.id and audit_log.operation='D' and

Re: SQL help

2004-06-03 Thread Egor Egorov
Bob Lockie [EMAIL PROTECTED] wrote: What I really want was mysql update records set records.prio=2 where records.in=(select records.id from records, audit_log, audit_log_records where audit_log.tracker_id=audit_log_records.tracker_id and records.id=audit_log_records.id and

RE: SQL-help needed

2004-02-19 Thread Ligaya Turmelle
I'm still a beginner myself but try something like SELECT COUNT(YEAR), WINNER1 AS WINNER, WINNER2 AS WINNER, YEAR FROM CHAMPIONS WHERE CLASS = hd GROUP BY WINNER; I think this will give you something like: COUNT(YEAR) WINNER YEAR 2 carl

Re: SQL-help needed

2004-02-19 Thread Michael Stassen
Carl Schéle, IT, Posten wrote: Hi! I got a table, champions, looking like this: idclass winner_1 winner_2 year - 0 hd carl mattias 1957 1

Re: SQL-HELP

2004-02-17 Thread Jonas Lindén
Hello, you might want to try select DISTINCT ? http://www.mysqlfreaks.com/statements/18.php /Jonas - Original Message - From: Carl Schéle, IT, Posten [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, February 17, 2004 3:49 PM Subject: SQL-HELP Hello! I got a table, champions,

Re: SQL-HELP

2004-02-17 Thread Jochem van Dieten
Carl Schéle, IT, Posten wrote: I got a table, champions, looking like this: id winner_1 winner_2 0carl mattias 1daniel carl 2

Re: SQL Help

2004-01-16 Thread Roger Baklund
* sulewski [...] What I need is all records in table 1 that will not link to table 2 such that relid=rid and vid=46 Sounds like a job for LEFT JOIN...? Join to the rows you do NOT want with a left join, and put as a condition in the WHERE clause that a joined column IS NULL. Something like

Re: SQL Help

2004-01-16 Thread sulewski
Roger, Thank you for the feedback. But unfortunately this doesn't work. The problem is that rid will never be null. I'm trying to find the item in tab1 where a link cannot be created in tab2 where tab2.rid=tab1.id and tab2.vid=46 because there is no record in tab2. Not that the record may

Re: SQL Help

2004-01-16 Thread sulewski
Roger, In regards to my last e-mail what would be great is if I can get all the records in tab1 then subtract from there all the records that match the query tab1.id=tab2.rid and tab2.vid=46. The result would give me what I need but alas mysql doesn't support minus. Joe On Friday, January

Re: SQL Help

2004-01-16 Thread gerald_clark
That is the whole point of a left join. It joins to a null record when the appropriate right record does not exist. sulewski wrote: Roger, Thank you for the feedback. But unfortunately this doesn't work. The problem is that rid will never be null. I'm trying to find the item in tab1 where a

Re: SQL Help

2004-01-16 Thread sulewski
Gerald, Your right. You and Roger hit it on the head. Stupid me miss read Roger's original post. Last night I was banging my head on the left and right joins but I didn't understand it until I read Gerald's last note. Plus I didn't realize you can put two conditions in the ON clause which is

Re: SQL Help...

2003-07-25 Thread Info
Estoy tomando el sol . q -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]

Re: SQL Help...

2003-07-25 Thread Info
Estoy tomando el sol . q -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]

RE: SQL Help...

2003-07-24 Thread Dathan Vance Pattishall
---Original Message- --From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] --Sent: Thursday, July 24, 2003 12:53 PM --To: [EMAIL PROTECTED] --Subject: SQL Help... -- --After some searching around different books/manuals/google I still can't --seem to figure out how do to this. What I have

Re: SQL Help...

2003-07-24 Thread mos
At 02:52 PM 7/24/2003, you wrote: After some searching around different books/manuals/google I still can't seem to figure out how do to this. What I have is a table with 4 cols (task, resource, department, priority) and what I want to do is be able to select distinct resources and list what their

RE: SQL Help...

2003-07-24 Thread nick
I looked at the group by option already and I dont think it will do what I need it to do. I say this because it will only group things in the priority/task/whatever but that still leaves options for duplicate resources. Yes, it would get rid of the dup. resources per priority, but not for the

RE: SQL Help...

2003-07-24 Thread Cabanillas Dulanto, Ulises
Try: select task, resource, department, max(priority) from table group by task, resource, department Regards, Ulises -Mensaje original- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Enviado el: Jueves 24 de Julio de 2003 02:53 PM Para: [EMAIL PROTECTED] Asunto: SQL Help... After

Re: SQL Help...

2003-07-24 Thread nick
That works great. =D Knew it shouldn't be that difficult, thanks a bunch. And it actually works with the Priorities being in text form to (low, med, hi). -Nick At 02:52 PM 7/24/2003, you wrote: After some searching around different books/manuals/google I still can't seem to figure out how do to

RE: SQL Help...

2003-07-24 Thread Lin Yu
To: Dathan Vance Pattishall Cc: [EMAIL PROTECTED] Subject: RE: SQL Help... I looked at the group by option already and I dont think it will do what I need it to do. I say this because it will only group things in the priority/task/whatever but that still leaves options for duplicate resources. Yes

RE: SQL Help...

2003-07-24 Thread nick
PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, July 24, 2003 4:41 PM To: Dathan Vance Pattishall Cc: [EMAIL PROTECTED] Subject: RE: SQL Help... I looked at the group by option already and I dont think it will do what I need it to do. I say this because it will only group things

Re: sql help

2002-12-23 Thread William R. Mussatto
You want to look at 'group by acctSrv.accountID' rather than a compound select. On Mon, 23 Dec 2002, Adam Nowalsky wrote: Date: Mon, 23 Dec 2002 09:04:32 -0500 From: Adam Nowalsky [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: sql help hi, wonder if the sql gurus can help with this

Re: SQL Help Needed

2002-05-23 Thread Nick Stuart
Ok this should be easy so I'm prolly going to screw it up, but here goes =D Your query should be: SELECT UserID, SUM(points) FROM History WHERE WeekID = 'whatever' GROUP BY UserIdI think that should do it. Someone yell if its wrong though. -Nick I have 2 tables Users (UserID) History

RE: SQL Help Needed

2002-05-23 Thread Roger Baklund
* Dave I have 2 tables Users (UserID) History (UserID, WeekID, Points) When a User record is created a record is inserted into History with the current WeekID, so for example data could be : Users History -- - 1 - 10 - 1 - 20

Re: SQL Help Needed

2002-05-23 Thread Dave
exist for WeekID = 2, other for 1 and 2 and so on. Cheers Dave - Original Message - From: Roger Baklund [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: Dave [EMAIL PROTECTED] Sent: Thursday, May 23, 2002 6:21 PM Subject: RE: SQL Help Needed * Dave I have 2 tables Users (UserID

RE: SQL Help Needed

2002-05-23 Thread Roger Baklund
* Dave Thanks for your responses but it's not that much help I need with my SQL ;-) None of the 3 suggestions work. Please look at the examples I gave. I need *all* UserIDs regardless of whether they have a record in History that matches both UserID and WeekID. ...and that is what I

RE: sql help examining log table

2002-03-17 Thread Dan Vande More
I might be wrong, but this may get you going in the right direction: select count(subject) as count, subject from outgoing where auth='USER' group by subject order by timestamp desc limit 50 This would tell you each subject ever sent by the user, and how many times that subject has been sent.

RE: sql help examining log table

2002-03-17 Thread Dan Vande More
of coffee:) -Original Message- From: Dan Vande More [mailto:[EMAIL PROTECTED]] Sent: Sunday, March 17, 2002 1:44 PM To: [EMAIL PROTECTED] Subject: RE: sql help examining log table I might be wrong, but this may get you going in the right direction: select count(subject) as count, subject from

Re: sql help examining log table

2002-03-17 Thread Anvar Hussain K.M.
Hi Viraj, You can do it using temporary table. Create temporary table tmp select subject from outgoing where auth='USER' order by timestamp desc limit 50; Select count(distinct subject) from tmp group by subject; drop table tmp; If the result of the second query is 1 all the last 50 messages

Re: SQL Help, Please...

2002-02-14 Thread Tod Harter
On Thursday 14 February 2002 07:58, Carl Shelbourne wrote: Hi I am trying to write an auction script that uses mysql as its backend. Each auction can have upto 25 sub auctions(cells) taking place. I'm trying to query the DB to give me a list of all the successfull bids for each cell, for

Re: SQL Help, Please...

2002-02-14 Thread Anvar Hussain K.M.
Hi, At 11:21 AM 14/02/2002 -0500, you wrote: On Thursday 14 February 2002 07:58, Carl Shelbourne wrote: Hi I am trying to write an auction script that uses mysql as its backend. Each auction can have upto 25 sub auctions(cells) taking place. I'm trying to query the DB to give me a

Re: SQL help plz

2002-01-30 Thread Paul DuBois
At 21:36 +0200 1/30/02, P.Agenbag wrote: Hi I need help with an sql string: have a table similar to this: idkeynamedate 1 123name1 date1 2 123name1 date2 3 111name2 date1 4 111name2 date2

RE: SQL help plz

2002-01-30 Thread Rick Emery
mysql describe mytable; +---+--+--+-+-+---+ | Field | Type | Null | Key | Default | Extra | +---+--+--+-+-+---+ | id| int(11) | YES | | NULL| | | keyq | int(11) | YES | | NULL| | | name |

RE: SQL help plz

2002-01-30 Thread Rick Emery
Sorry, I meant: mysql select name,max(dateq) from mytable group by keyq; -Original Message- From: Rick Emery Sent: Wednesday, January 30, 2002 2:14 PM To: 'P.Agenbag'; mysql Subject: RE: SQL help plz mysql describe mytable; +---+--+--+-+-+---+ | Field

RE: SQL help plz

2002-01-30 Thread Rick Emery
Further, I'd advise NOT using field names like date and key. Using eserved words is never a good prcatice. -Original Message- From: Rick Emery Sent: Wednesday, January 30, 2002 2:16 PM To: 'P.Agenbag'; 'mysql' Subject: RE: SQL help plz Sorry, I meant: mysql select name,max(dateq

Re: SQL help plz

2002-01-30 Thread Steve Severance
Try this: select key_col, min(name), max(date_col) from my_table group by key_col ; You could use max(name) instead of min(name) also, although since the names can be misspelled, I don't see why it would matter which name is displayed. s.s. On Wed, 30 Jan 2002

Re: SQL help

2001-05-08 Thread Zak Greant
SELECT * FROM db ORDER BY rand() LIMIT 5 --zak - Original Message - From: Webmaster [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, May 08, 2001 9:38 PM Subject: SQL help How do I write SQL in MySQL to randomly select 5 records from a table?

Re: SQL help

2001-05-08 Thread Tony Shiu
i think it is more suitable to do it in programming level in mysql, though I know there is a function is M$sql server. if your table schema has a unique id field, before submit a query to DB, 1) select count(*) from it 2) from the above resultset, program to draw whatever number of records you

Re: SQL help

2001-05-08 Thread Webmaster
i dont follow step #3. At 11:42 PM 5/8/2001, Tony Shiu wrote: i think it is more suitable to do it in programming level in mysql, though I know there is a function is M$sql server. if your table schema has a unique id field, before submit a query to DB, 1) select count(*) from it 2) from

Re: SQL help

2001-05-08 Thread Tony Shiu
using primary key of your table. mine works in both old and new versions. - Original Message - From: Webmaster [EMAIL PROTECTED] To: Tony Shiu [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, May 09, 2001 12:27 PM Subject: Re: SQL help i dont follow step #3. At 11:42 PM 5/8

Re: SQL help

2001-05-08 Thread j.urban
You might be able to do something like this instead: SELECT *, id*0+RAND() AS r FROM table ORDER BY r LIMIT 5; Check the list archives, this issue comes up quite often. On Wed, 9 May 2001, Webmaster wrote: i dont follow step #3. At 11:42 PM 5/8/2001, Tony Shiu wrote: i think it is

Re: SQL HELP

2001-01-16 Thread Cindy
"j.urban" writes: select field1,field2,DATE_FORMAT(datefield,"%M %d, %Y"),field4,fieldn from table; He didn't want to have to explicitly list all 40 other fields, though. Can't he do something like SELECT *.DATE_FORMAT(datefield, "%M %d, %Y") FROM table; ? That gives him one extra field,