Re: SQL query question for GROUP BY

2008-04-15 Thread Perrin Harkins
On Fri, Apr 11, 2008 at 4:01 PM, Victor Danilchenko <[EMAIL PROTECTED]> wrote: > Oooh, this looks evil. It seems like such a simple thing. I guess > creating max(log_date) as a field, and then joining on it, is a solution -- > but my actual query (not the abridged version) is already half a

Re: SQL query question for GROUP BY

2008-04-15 Thread Victor Danilchenko
I just thought of something else... could the same be accomplished using stored routines? I could find no way in MySQL to create stored routines which could be used with the 'group by' queries though. If this were possible, it should then be also possible to define a 'LAST' stored routine, o

Re: SQL query question for GROUP BY

2008-04-11 Thread Rob Wultsch
On Fri, Apr 11, 2008 at 1:01 PM, Victor Danilchenko <[EMAIL PROTECTED]> wrote: > Oooh, this looks evil. It seems like such a simple thing. I guess > creating max(log_date) as a field, and then joining on it, is a solution -- > but my actual query (not the abridged version) is already half a

Re: SQL query question for GROUP BY

2008-04-11 Thread Victor Danilchenko
Oooh, this looks evil. It seems like such a simple thing. I guess creating max(log_date) as a field, and then joining on it, is a solution -- but my actual query (not the abridged version) is already half a page long. I think at this point, unless someone else suggests a better solution, th

Re: SQL query question for GROUP BY

2008-04-11 Thread Rob Wultsch
On Fri, Apr 11, 2008 at 11:46 AM, Victor Danilchenko <[EMAIL PROTECTED]> wrote: > GROUP BY seems like an obvious choice; 'GROUP BY username', to be > exact. However, this seems to produce not the last row's values, but ones > from a random row in the group. Under most databases your query i

RE: SQL Query Question

2007-01-21 Thread Adam Bishop
Ah, that would work. Looks like I was making the problem too complex in my mind, thanks for your help. Adam Bishop -Original Message- From: Dan Nelson [mailto:[EMAIL PROTECTED] Sent: 22 January 2007 07:07 To: Adam Bishop Cc: mysql@lists.mysql.com Subject: Re: SQL Query Question In the

Re: SQL Query Question

2007-01-21 Thread Dan Nelson
In the last episode (Jan 22), Adam Bishop said: > If I have a dataset as below: > > Name, Age, Word > > Bob, 13, bill > Joe, 13, oxo > Alex, 14, thing > Jim, 14, blob > Phil, 14, whatsit > Ben, 15, doodah > Rodney, 15, thingy > > I want to select the first block where

Re: SQL Query Question

2004-08-14 Thread Michael Stassen
Right. If the employee ID in either the rep_no or entered_by columns does not have a corresponding row in the global_employee table, then the regular join won't match that row. In that case, as you found, you need a LEFT JOIN, which guarantees you get the rows from the table on the left, and

Re: SQL Query Question

2004-08-14 Thread Michael J. Pawlowsky
Thanks a lot Michael. A regular join did not seem to work. But when I tried a LEFT JOIN it worked. A cut down example of it is the following. SELECT global_lead.id, rep_no, es.fname as sales_name, em.fname as marketing_name FROM global_lead LEFT JOIN global_employee es ON global_lead.rep_no = es.i

Re: SQL Query Question

2004-08-14 Thread Michael Stassen
You need to join the employee table twice, once for each id lookup, like this: SELECT es.name AS sales_name, em.name AS marketing_name, leads.id FROM leads JOIN employee es ON leads.salesid = es.id JOIN employee em ON leads.marketingid = em.id; Michael Michael J. Pawlowsky wrote: I

Re: SQL Query Question

2004-04-17 Thread Michael Stassen
If you do any math on your column, no index on the column can be used. If possible, you should always try to write your condition so that the calculations are done on the value(s) to compare to, not on the column. So, assuming you have no rows with future timestamps, something like this should

RE: SQL Query Question

2004-04-17 Thread Victor Pendleton
The you will need to use the second format. DATE_FORMAT(queue_time, '%Y%m%d') = CURRENT_DATE() -Original Message- From: Dirk Bremer (NISC) To: [EMAIL PROTECTED] Sent: 4/16/04 4:09 PM Subject: Re: SQL Query Question - Original Message - From: "Victor Pendleton&quo

Re: SQL Query Question

2004-04-16 Thread Garth Webb
On Fri, 2004-04-16 at 14:09, Dirk Bremer (NISC) wrote: > - Original Message - > From: "Victor Pendleton" <[EMAIL PROTECTED]> > To: "'Dirk Bremer (NISC) '" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > Sent: Friday, April 16, 2004 15

Re: SQL Query Question

2004-04-16 Thread Dirk Bremer \(NISC\)
- Original Message - From: "Victor Pendleton" <[EMAIL PROTECTED]> To: "'Dirk Bremer (NISC) '" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, April 16, 2004 15:57 Subject: RE: SQL Query Question > If your data is stored in the

RE: SQL Query Question

2004-04-16 Thread Victor Pendleton
27;%Y%m%d') = CURRENT_DATE() + 0 ...no index usage though -Original Message- From: Dirk Bremer (NISC) To: [EMAIL PROTECTED] Sent: 4/16/04 3:25 PM Subject: Re: SQL Query Question - Original Message - From: "Victor Pendleton" <[EMAIL PROTECTED]> To: "

Re: SQL Query Question

2004-04-16 Thread Dirk Bremer \(NISC\)
- Original Message - From: "Victor Pendleton" <[EMAIL PROTECTED]> To: "'Dirk Bremer (NISC) '" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, April 16, 2004 15:06 Subject: RE: SQL Query Question > WHERE queue_time = Now()

RE: SQL Query Question

2004-04-16 Thread Victor Pendleton
WHERE queue_time = Now() + 0 Are you wanting just the date or the datetime? -Original Message- From: Dirk Bremer (NISC) To: [EMAIL PROTECTED] Sent: 4/16/04 2:54 PM Subject: SQL Query Question I have a simple table where one of the columns is named queue_time and is defined as a timestamp-

RE: SQL Query Question

2004-04-16 Thread Scott Purcell
This works for Oracle, give it a try, use any format you want for the MM/DD/YY area. select to_char(queue_time, 'MM/DD/YY'); Scott Purcell -Original Message- From: Dirk Bremer (NISC) [mailto:[EMAIL PROTECTED] Sent: Friday, April 16, 2004 2:55 PM To: [EMAIL PROTECTED] Subject: SQL Quer

Re: SQL Query Question

2004-01-20 Thread sulewski
I think I figured out the time problem. If I make s2 in the or s1 and remove any instances of s2 it works very fast with the 'or'. Joe On Tuesday, January 20, 2004, at 09:50 AM, sulewski wrote: Hello, For my final solution I decided to use the inner join method. The query is created dynamica

Re: SQL Query Question

2004-01-20 Thread sulewski
Hello, For my final solution I decided to use the inner join method. The query is created dynamically based upon a user interface component that allows people to build queries using parenthesis, ands and or's. Plus there is another field that I didn't include in the original question so as to

Re: SQL Query Question

2004-01-19 Thread Jochem van Dieten
Michael Satterwhite wrote: On Monday 19 January 2004 16:30, Jochem van Dieten wrote: Michael Satterwhite said: On Monday 19 January 2004 15:38, Jochem van Dieten wrote: So let's make it 2 fields: SELECT t1.* FROM table1 t1, table2 t2 INNER JOIN table2 t3 ON (t2.rdid = t3.rdid AND t2.vid =

Re: SQL Query Question

2004-01-19 Thread Michael Satterwhite
On Monday 19 January 2004 16:30, Jochem van Dieten wrote: > Michael Satterwhite said: > > On Monday 19 January 2004 15:38, Jochem van Dieten wrote: > >> So let's make it 2 fields: > >> > >> SELECT > >> t1.* > >> FROM > >> table1 t1, > >> table2 t2 INNER JOIN table2 t3 > >>ON (t2.rdid = t3

Re: SQL Query Question

2004-01-19 Thread Jochem van Dieten
Michael Satterwhite said: > On Monday 19 January 2004 15:38, Jochem van Dieten wrote: >> So let's make it 2 fields: >> >> SELECT >> t1.* >> FROM >> table1 t1, >> table2 t2 INNER JOIN table2 t3 >>ON (t2.rdid = t3.rdid AND t2.vid = 46 AND t3.vid = 554) >> WHERE >> t1.rdid = t2.rdid >> >>

Re: SQL Query Question

2004-01-19 Thread Michael Satterwhite
On Monday 19 January 2004 15:38, Jochem van Dieten wrote: > So let's make it 2 fields: > > SELECT > t1.* > FROM > table1 t1, > table2 t2 INNER JOIN table2 t3 >ON (t2.rdid = t3.rdid AND t2.vid = 46 AND t3.vid = 554) > WHERE > t1.rdid = t2.rdid > > Add GROUP BY/DISTINCT per your requireme

RE: SQL Query Question

2004-01-19 Thread Jochem van Dieten
Lincoln Milner said: > Or, if I'm not mistaken, you could do something like: > SELECT t1.* > FROM table1 t1, table2 t2 > WHERE t1.id = t2.rdid >AND t2.vid IN (46, 554) > ; > > That should work No. You are back to square one where there should only be one record in t2 with a vid of either 46

Re: SQL Query Question

2004-01-19 Thread sulewski
Jochem, I believe this works. This is also easy to build dynamically. The query is going to be generated based upon some user input. Thank you very much, Joe On Monday, January 19, 2004, at 04:38 PM, Jochem van Dieten wrote: Michael Satterwhite said: On Monday 19 January 2004 13:17, sulewski

RE: SQL Query Question

2004-01-19 Thread Lincoln Milner
ssage- From: Jochem van Dieten [mailto:[EMAIL PROTECTED] Sent: Monday, January 19, 2004 4:39 PM To: [EMAIL PROTECTED] Subject: Re: SQL Query Question Michael Satterwhite said: > On Monday 19 January 2004 13:17, sulewski wrote: >> Okay, I think I'm missing something obvious.

Re: SQL Query Question

2004-01-19 Thread Jochem van Dieten
Michael Satterwhite said: > On Monday 19 January 2004 13:17, sulewski wrote: >> Okay, I think I'm missing something obvious. I have two tables >> >> Table 1 Table 2 >> ___ _ >> ID rdid vid

Re: SQL Query Question

2004-01-19 Thread Michael Satterwhite
On Monday 19 January 2004 13:17, sulewski wrote: > Okay, I think I'm missing something obvious. I have two tables > > Table 1 Table 2 > ___ _ > ID rdid vid > ___ _

Re: SQL Query Question

2004-01-19 Thread sulewski
Let me post the question this way, MyTable --- pointerid valueid 811 54 811 63 812 100 813 200 814 300 815 400 I want all the records in MyTable w

Re: SQL query question

2003-11-11 Thread Leo
try group by SELECT firmal.beskrivelse as Businessline, lokasjon.navn as Location, count(person.name) as "Sum People" FROM firmal INNER JOIN ( person INNER JOIN lokasjon ON person.lokid = lokasjon.lokid) ON firmal.firmalid = person.firmalid group by firmal.beskrivelse, lokasjon.navn -leo- From:

RE: SQL query question

2003-11-11 Thread Paal Eriksen
So close, Thanks you very much Andy. I tried one similar to your suggestion, but didn't get quite the result i expected. Cheers Paal Ny versjon av Yahoo! Messenger Nye ikoner og bakgrunner, webkamera med superkvalitet og dobbelt så morsom

RE: SQL query question

2003-11-11 Thread Andy Eastham
Pael, Try this: SELECT firmal.beskrivelse as Businessline, lokasjon.navn as Location, count(person.[uniqueid]) FROM firmal INNER JOIN ( person INNER JOIN lokasjon ON person.lokid = lokasjon.lokid) ON firmal.firmalid = person.firmalid GROUP BY firmal.beskrivelse, lokasjon.navn Replace [uniqueid]

RE: SQL query question

2003-06-20 Thread TheMechE
Rolf, You need to separate your functions. You are adding complexity to your world by storing irrelvant infromation in your database. Critical Data Handling (in a proper world) is ALWAYS handled separately from display. So in your example, You are storing all the html display formatting in your

RE: SQL query question

2003-06-19 Thread Mike Hillyer
Well, from what limited info I have, it looks like your image tag is not closed properly. Regards, Mike Hillyer www.vbmysql.com > -Original Message- > From: Rolf C [mailto:[EMAIL PROTECTED] > Sent: Thursday, June 19, 2003 2:57 PM > To: [EMAIL PROTECTED] > Subject: SQL query question >

Re: SQL query question - using LIKE

2002-03-28 Thread DL Neil
ECTED]>; "MySQL" <[EMAIL PROTECTED]> Sent: 28 March 2002 19:16 Subject: Re: SQL query question - using LIKE > DL - > > Points well taken - > I am using php and doing simple validation > EX - if ($fname !="") { > add fname string to search variabl

Re: SQL query question - using LIKE

2002-03-28 Thread Mark Stringham
en me enough to work with. But I am certainly open for more suggestion/ feedback. Thanks Mark -Original Message- From: DL Neil <[EMAIL PROTECTED]> To: Peter Lovatt <[EMAIL PROTECTED]>; Mark Stringham <[EMAIL PROTECTED]>; MySQL <[EMAIL PROTECTED]> Date: Thursday, Ma

Re: SQL query question - using LIKE

2002-03-28 Thread DL Neil
Mark, Peter, The query below assumes that the user will search of FirstName and none or more of the other fields - which was not how the question reads (to me). To answer the question it would be useful to know how you are accessing MySQL - are you using PHP (as per example code below) for examp

RE: SQL query question - using LIKE

2002-03-28 Thread Peter Lovatt
Hi $query = 'SELECT * FROM Table WHERE FirstName LIKE "%'.$firstname.'%"' ; if($lastname)$query.= ', AND LastName LIKE "%'.$lastname.'%"'; if($region)$query.= ', AND Region LIKE "%'.$region.'%"'; if($loan_officer)$query.

Re: SQL query question?

2001-04-05 Thread Steve Werby
It's not possible to do in one step in MySQL. -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ "roger westin" <[EMAIL PROTECTED]> wrote: So a question I have two tables. And i want to... (i just show you) Table 1. OwnerChar(30)Uniqe FileChar