If`s in MySQL.... Having some trouble here...
| From: | Trond Erling Hundal | Date: | Fri, 16 Mar 2001 11:31:01 +0000 |
| Subject: | If`s in MySQL.... Having some trouble here... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-7543@lists.php.net to get a copy of this message | ||
Hi there...
I want to query two tables in my db. One containing a list of numbers
ranging from 10000 - 10200, the other table is storing information that is
relative to some of the numbers:
Eks:
Table1.record1: number=10000
Table2.record1: number=10000 name=John
Now I want to query these to tables to show a table that has one column with
the numbers, and if there is a name stored in the other table for this
number, I want to display this.
(
So.
I have been doodling with an "if" thingy in MySQL, but I am having trouble
getting result I need.
select
table1.number,
IF(table1.number = table2.number AND table2.name = NULL,
'No name registered',
table2.name)
FROM table1,
table2
LIMIT 0,30
What am I doing wrong here... It only displays the first name stored in the
table...?
- Trond -