RE: [PHP] Re: logic operands problem
Um, yes, probably need to update my Oracle reference manuals – I think the big fat paper one on my shelf may even refer to ANSI SQL89, which I suspect is pretty much what my head content is based on also. In any case, XOR doesn’t appear to be in the latest ANSI/ISO SQL standards I have access to (ANSI 2003), so this may be a MySQL-specific extension. But however you slice it, XOR is the wrong solution for the problem at hand! ;) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: 07 December 2009 12:26 To: Ford, Mike Cc: php-general@lists.php.net Subject: RE: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:26 +, Ford, Mike wrote: This is pretty much why SQL does not offer you the XOR operator! Someone better tell the MySQL developers then... http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html Thanks, Ash http://www.ashleysheridan.co.uk To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
RE: [PHP] Re: logic operands problem
On Mon, 2009-12-07 at 12:26 +, Ford, Mike wrote: > This is pretty much why SQL does not offer you the XOR operator! Someone better tell the MySQL developers then... http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] Re: logic operands problem
> -Original Message- > From: Merlin Morgenstern [mailto:merli...@fastmail.fm] > Sent: 07 December 2009 11:52 > To: "Sándor Tamás (HostWare Kft.)" > Cc: Merlin Morgenstern; php-general@lists.php.net > Subject: Re: [PHP] Re: logic operands problem > > > > Sándor Tamás (HostWare Kft.) wrote: > > I don't really get it. This is a select statement working with the > > datas of one table. > > A field of a record (namely "page" here) can only take one value, > so > > it is totally nonsense to give XOR for that field. > > > > I think you want to select two different recordsets: one with page > 1 > > and 3, and another with 2 and 3, am I right? > > > > SanTa > > > Yes, you are right. Any ideas on how to do this within one query? If you need these two specific recordsets, I don't see how you can. You'll have to make two queries and do any further logic in PHP using the two sets of results. XOR is a total nonsense in this situation -- as your condition is targeting a single, single-valued field, the value you are testing cannot possibly be simultaneously both 1 and 2, so the XOR operator is essentially redundant and effectively the same as the OR operator. This is pretty much why SQL does not offer you the XOR operator! All of the condition variants I've seen in this thread so far pretty much boil down to (page=1 OR page=2 OR page=3), which, as you found, returns your entire database. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: logic operands problem
Sándor Tamás (HostWare Kft.) wrote: I don't really get it. This is a select statement working with the datas of one table. A field of a record (namely "page" here) can only take one value, so it is totally nonsense to give XOR for that field. I think you want to select two different recordsets: one with page 1 and 3, and another with 2 and 3, am I right? SanTa Yes, you are right. Any ideas on how to do this within one query? - Original Message - From: "Ashley Sheridan" To: "Merlin Morgenstern" Cc: "Peter Ford" ; Sent: Monday, December 07, 2009 12:39 PM Subject: Re: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: > Merlin Morgenstern wrote: >> Hello everybody, >> >> I am having trouble finding a logic for following problem: >> >> Should be true if: >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = >> 3 >> >> The result should never contain 1 AND 2 in the same time. >> >> This obviously does not work: >> (page = 1 OR page = 3) OR (page = 2 OR page = 3) >> >> This also does not work: >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page >> != 1) >> >> Has somebody an idea how to solve this? >> >> Thank you in advance for any help! >> >> Merlin > > > Surely what you need is xor (exclusive-or) > I can't believe a programmer has never heard of that! > > (page==1 XOR page==2) AND page==3 > HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: logic operands problem
Ashley Sheridan wrote: On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: > Merlin Morgenstern wrote: >> Hello everybody, >> >> I am having trouble finding a logic for following problem: >> >> Should be true if: >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 >> >> The result should never contain 1 AND 2 in the same time. >> >> This obviously does not work: >> (page = 1 OR page = 3) OR (page = 2 OR page = 3) >> >> This also does not work: >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page >> != 1) >> >> Has somebody an idea how to solve this? >> >> Thank you in advance for any help! >> >> Merlin > > > Surely what you need is xor (exclusive-or) > I can't believe a programmer has never heard of that! > > (page==1 XOR page==2) AND page==3 > HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk Exactly! This is unfortunatelly what happens! Any ideas how to get the correct results?
Re: [PHP] Re: logic operands problem
I don't really get it. This is a select statement working with the datas of one table. A field of a record (namely "page" here) can only take one value, so it is totally nonsense to give XOR for that field. I think you want to select two different recordsets: one with page 1 and 3, and another with 2 and 3, am I right? SanTa - Original Message - From: "Ashley Sheridan" To: "Merlin Morgenstern" Cc: "Peter Ford" ; Sent: Monday, December 07, 2009 12:39 PM Subject: Re: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: > Merlin Morgenstern wrote: >> Hello everybody, >> >> I am having trouble finding a logic for following problem: >> >> Should be true if: >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = >> 3 >> >> The result should never contain 1 AND 2 in the same time. >> >> This obviously does not work: >> (page = 1 OR page = 3) OR (page = 2 OR page = 3) >> >> This also does not work: >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page >> != 1) >> >> Has somebody an idea how to solve this? >> >> Thank you in advance for any help! >> >> Merlin > > > Surely what you need is xor (exclusive-or) > I can't believe a programmer has never heard of that! > > (page==1 XOR page==2) AND page==3 > HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: logic operands problem
On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: > Peter Ford wrote: > > Merlin Morgenstern wrote: > >> Hello everybody, > >> > >> I am having trouble finding a logic for following problem: > >> > >> Should be true if: > >> page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 > >> > >> The result should never contain 1 AND 2 in the same time. > >> > >> This obviously does not work: > >> (page = 1 OR page = 3) OR (page = 2 OR page = 3) > >> > >> This also does not work: > >> (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page > >> != 1) > >> > >> Has somebody an idea how to solve this? > >> > >> Thank you in advance for any help! > >> > >> Merlin > > > > > > Surely what you need is xor (exclusive-or) > > I can't believe a programmer has never heard of that! > > > > (page==1 XOR page==2) AND page==3 > > > > HEllo Peter, > > thank you for your reply. I know about XOR, but unfortunatelly I might > not know how to use it properly OR it is not aplicable on SQL. I am > trying to retrive data: > SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) > > I know this is not php, but I thought the logic should be the same in > this case?! > > Regards, Merlin > This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk