RE: [PHP-DB] find a value in entire table...
| From: | Juffermans, Jos | Date: | Wed, 06 Apr 2005 14:03:35 +0000 |
| Subject: | RE: [PHP-DB] find a value in entire table... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-39135@lists.php.net to get a copy of this message | ||
Hi,
You could do something like this:
SELECT 'Accounts' as department, Accounts as id FROM mytable WHERE Accounts
IS NOT NULL
UNION ALL
SELECT 'Human Resources' as department, HR as id FROM mytable WHERE HR IS
NOT NULL
UNION ALL
SELECT 'Support' as department, Support as id FROM mytable WHERE Support IS
NOT NULL
UNION ALL
SELECT 'Marketing' as department, Marketing as id FROM mytable WHERE
Marketing IS NOT NULL
Replace "mytable" with your tablename.
I know it works on Oracle and I've just tested in on MySql and that works
good too. The query above returned this:
department | id
----------------|----
Accounts | 23
Accounts | 19
Human Resources | 17
Support | 17
Marketing | 4
Jos
-----Original Message-----
From: Tristan.Pretty@risk.sungard.com
[mailto:Tristan.Pretty@risk.sungard.com]
Sent: 06 April 2005 14:52
To: php-db@lists.php.net
Subject: [PHP-DB] find a value in entire table...
I need to search an entire table for a value, and then report back what
field it was found in... how on earth do I do that?
I've a list of departments, as field names.
whenever a user interacts with that Dpet, I wanna add thier id No to the
appropriate field.
so I'll be left with a table that looks like this:
================================
| Accounts | HR | Support | Marketing |
--------------------------------------------------------
| 23 | | | |
| | 17 | | |
| | | 17 | |
| 19 | | | |
| | | | 4 |
================================
So User 17 has dealt with HR and Support, and user 23 has dealt with only
Accounts.
So I wanna input an user ID no, and then get told what Dpets have been
accessed...
I need to learn this, as I know it's simple, but I've never had to do it
before!
Tris....
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php