Re: A difficult query- urgent for me

2006-01-15 Thread Jochem van Dieten
On 1/15/06, [EMAIL PROTECTED] wrote:

 Actually there is a table with columns a and b .
 So i want if a contains a particular word than a's value should return else
 'b' value should return.

SELECT
  CASE
WHEN a = 'Good' THEN a
ELSE b
  END
FROM
  table

Jochem


Re: A difficult query- urgent for me

2006-01-15 Thread Rhino

An example of the _data_ would be very helpful here.

For example, let's say this is your data:

Col_ACol_B
-----
aceexpert
doghound
hungryravenous

If you are searching for the word ace, you should find it. You then want 
the SQL to return ace, right?


If you are searching for the word puppy, you won't find it in the first 
column. Which word from the second column do you want to return??? There is 
no obvious reason to prefer any of the different values in the second column 
when the search word does not appear in the first column.


Or do you only have a single row in this table? If so, I'm not sure why you 
want to create a table just to contain these two values; it might be 
justified, depending on what you are doing, but it seems unlikely.


Can you clarify what you are trying to accomplish? Otherwise, it's going to 
be hard to help you.


Also, which version of MySQL are you on, 4.0.x or 4.1.x? It might make a big 
difference to the answer I would give since 4.0.x does not support 
subqueries while 4.1.x does.


Rhino

- Original Message - 
From: [EMAIL PROTECTED]

To: mysql@lists.mysql.com
Sent: Sunday, January 15, 2006 10:21 AM
Subject: A difficult query- urgent for me


Dear Friends,
I have a problm, try to solve that.
Actually there is a table with columns a and b .
So i want if a contains a particular word than a's value should return else
'b' value should return. And there must be one and only one column
returning. I have mysql 4.x and i think the logic will be like. I know i am
wrong by syntax but ...
SELECT IF(a REGEXP CONCAT('word' , '$'),a,b) from table_name where a =
'anything';

I think i am clear if not do please ask me questions.
I shall be very grateful if any one of you can give me a solutions.
--
Regards
Abhishek jain.


mail2web - Check your email from the web at
http://mail2web.com/ .



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.18/230 - Release Date: 14/01/2006




--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.18/230 - Release Date: 14/01/2006


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]