Re: where clause structures

2002-08-19 Thread Keith C. Ivey

On 19 Aug 2002, at 9:36, Aleksandar Bradaric wrote:

> It's that OR that makes the mess. Try with:
> 
> ->   WHERE CompanyDetails.CompanySuspended='0' AND
> -> CompanyDNSZones.ZoneName='megalan.co.za' AND
> -> (CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
> ->  CompanyDNSZones.ZoneServices LIKE '%HasMailingList%');

Since any string that contains 'HasMailingList' also contains 
'HasMail', there's no point in adding the last bit.  This should return 
the same results more efficiently:

   WHERE CompanyDetails.CompanySuspended='0' AND
 CompanyDNSZones.ZoneName='megalan.co.za' AND
 CompanyDNSZones.ZoneServices LIKE '%HasMail%';

If it's necessary to distinguish between 'HasMail' and 'HasMailingList' 
(as it presumably would be in other queries), then you can't use LIKE.  
Use FIND_IN_SET() instead (or rename the set elements):

   WHERE CompanyDetails.CompanySuspended='0' AND
 CompanyDNSZones.ZoneName='megalan.co.za' AND
 ( FIND_IN_SET('HasMail', CompanyDNSZones.ZoneServices) OR
   FIND_IN_SET('HasMailList', CompanyDNSZones.ZoneServices) );

Another possibility is to do bit operations on the set.  In this case, 
HasMail is 1 and HasMailingList is 2, so the criteria should be

   WHERE CompanyDetails.CompanySuspended='0' AND
 CompanyDNSZones.ZoneName='megalan.co.za' AND
 CompanyDNSZones.ZoneServices & 3;

[Filter fodder: SQL]

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Tobacco Documents Online
http://tobaccodocuments.org

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: where clause structures

2002-08-19 Thread Aleksandar Bradaric

Hi,

->   WHERE CompanyDetails.CompanySuspended='0' AND
-> CompanyDNSZones.ZoneName='megalan.co.za' AND
-> CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
-> CompanyDNSZones.ZoneServices LIKE '%HasMailingList%';

> I explictly tell MySQL in my where clause to only return results where
> CompanyDNSZones.ZoneName='megalan.co.za', so where does it fall out
> returning lists.megalan.co.za as well?

It's that OR that makes the mess. Try with:

->   WHERE CompanyDetails.CompanySuspended='0' AND
-> CompanyDNSZones.ZoneName='megalan.co.za' AND
-> (CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
->  CompanyDNSZones.ZoneServices LIKE '%HasMailingList%');


Regards,
Sasa

»mysql, select, database«



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




where clause structures

2002-08-18 Thread Terence

try this:

selectwhere WHATEVER LIKE 'whatever%'

notice the '%' at the end not the beginning...hope this is what you
wanted...

lekker dag verder boet.

- Original Message -
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 18, 2002 5:54 AM
Subject: Re: where clause structures


EEK

Tables structures :P

mysql> describe CompanyDetails;
+---+---+--+-+-+
+
| Field | Type  | Null | Key | Default |
Extra  |
+---+---+--+-+-+
+
| CompanyID | tinyint(4) unsigned   |  | PRI | NULL|
auto_increment |
| CompanyActive | enum('1','0') |  | MUL | 0   |
|
| CompanySuspended  | enum('0','1','2','3','4','5') |  | MUL | 0   |
|


mysql> describe CompanyDNSZones;
+--+
---+--+-+-++
| Field| Type
| Null | Key | Default | Extra  |
+--+
---+--+-+-++
| ZoneID   | int(11)
|  | PRI | NULL| auto_increment |
| CompanyID| smallint(6)
|  | MUL | 0   ||
| ZoneName | varchar(250)
|  | UNI | ||
| ZoneServices |
set('HasMail','HasMailingList','HasBackupMail','IsMegaDNS','IsSecondary') |
| MUL |     |    |




- Original Message -
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 17, 2002 11:44 PM
Subject: where clause structures


> Lo everyone,
>
> I seem to be having a problem with the structuring of my query - more
> specifically, with the WHERE clause...
>
> mysql> SELECT ZoneName
> ->   FROM CompanyDNSZones
> ->   LEFT JOIN CompanyDetails ON
> CompanyDetails.CompanyID=CompanyDNSZones.CompanyID
> ->   WHERE CompanyDetails.CompanySuspended='0' AND
> -> CompanyDNSZones.ZoneName='megalan.co.za' AND
> -> CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
> -> CompanyDNSZones.ZoneServices LIKE '%HasMailingList%';
> +-+
> | ZoneName|
> +-+
> | megalan.co.za   |
> | lists.megalan.co.za |
> +-+
> 2 rows in set (0.01 sec)
>
> How do I get it to only return the item specified in the WHERE clause?
>
> I explictly tell MySQL in my where clause to only return results where
> CompanyDNSZones.ZoneName='megalan.co.za', so where does it fall out
> returning lists.megalan.co.za as well?
>
> --
> me
>
> PS: Just for interest takes, can LEFT / RIGHT / a combination of LEFT &
> RIGHT joins be used to cross-reference three or more tables, or is it
> limited to 2 tables only?
>
>
>
>
> -
> Before posting, please check:
>http://www.mysql.com/manual.php   (the manual)
>http://lists.mysql.com/   (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: where clause structures

2002-08-17 Thread Chris Knipe

EEK

Tables structures :P

mysql> describe CompanyDetails;
+---+---+--+-+-+
+
| Field | Type  | Null | Key | Default |
Extra  |
+---+---+--+-+-+
+
| CompanyID | tinyint(4) unsigned   |  | PRI | NULL|
auto_increment |
| CompanyActive | enum('1','0') |  | MUL | 0   |
|
| CompanySuspended  | enum('0','1','2','3','4','5') |  | MUL | 0   |
|


mysql> describe CompanyDNSZones;
+--+
---+--+-+-++
| Field| Type
| Null | Key | Default | Extra  |
+--+
---+--+-+-++
| ZoneID   | int(11)
|  | PRI | NULL| auto_increment |
| CompanyID| smallint(6)
|  | MUL | 0   ||
| ZoneName | varchar(250)
|  | UNI | ||
| ZoneServices |
set('HasMail','HasMailingList','HasBackupMail','IsMegaDNS','IsSecondary') |
| MUL | ||




- Original Message -
From: "Chris Knipe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 17, 2002 11:44 PM
Subject: where clause structures


> Lo everyone,
>
> I seem to be having a problem with the structuring of my query - more
> specifically, with the WHERE clause...
>
> mysql> SELECT ZoneName
> ->   FROM CompanyDNSZones
> ->   LEFT JOIN CompanyDetails ON
> CompanyDetails.CompanyID=CompanyDNSZones.CompanyID
> ->   WHERE CompanyDetails.CompanySuspended='0' AND
> -> CompanyDNSZones.ZoneName='megalan.co.za' AND
> -> CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
> -> CompanyDNSZones.ZoneServices LIKE '%HasMailingList%';
> +-+
> | ZoneName|
> +-+
> | megalan.co.za   |
> | lists.megalan.co.za |
> +-+
> 2 rows in set (0.01 sec)
>
> How do I get it to only return the item specified in the WHERE clause?
>
> I explictly tell MySQL in my where clause to only return results where
> CompanyDNSZones.ZoneName='megalan.co.za', so where does it fall out
> returning lists.megalan.co.za as well?
>
> --
> me
>
> PS: Just for interest takes, can LEFT / RIGHT / a combination of LEFT &
> RIGHT joins be used to cross-reference three or more tables, or is it
> limited to 2 tables only?
>
>
>
>
> -
> Before posting, please check:
>http://www.mysql.com/manual.php   (the manual)
>http://lists.mysql.com/   (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




where clause structures

2002-08-17 Thread Chris Knipe

Lo everyone,

I seem to be having a problem with the structuring of my query - more
specifically, with the WHERE clause...

mysql> SELECT ZoneName
->   FROM CompanyDNSZones
->   LEFT JOIN CompanyDetails ON
CompanyDetails.CompanyID=CompanyDNSZones.CompanyID
->   WHERE CompanyDetails.CompanySuspended='0' AND
-> CompanyDNSZones.ZoneName='megalan.co.za' AND
-> CompanyDNSZones.ZoneServices LIKE '%HasMail%' OR
-> CompanyDNSZones.ZoneServices LIKE '%HasMailingList%';
+-+
| ZoneName|
+-+
| megalan.co.za   |
| lists.megalan.co.za |
+-+
2 rows in set (0.01 sec)

How do I get it to only return the item specified in the WHERE clause?

I explictly tell MySQL in my where clause to only return results where
CompanyDNSZones.ZoneName='megalan.co.za', so where does it fall out
returning lists.megalan.co.za as well?

--
me

PS: Just for interest takes, can LEFT / RIGHT / a combination of LEFT &
RIGHT joins be used to cross-reference three or more tables, or is it
limited to 2 tables only?




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php