Saturday, November 10, 2007

Some notes on MySQL

1. how to check whether a field is NULL?
First, NULL in MySQL is not a value, it is a condition. So if you try and write something "= NULL" you'll get an empty set rather than the results you're looking for. Try "IS NULL" instead. For example, mysql> select * from demo_people left join demo_property on demo_people.pid = demo_property.pid where spid is NULL;

2. becaulful with this code:
while((row=mysql_fetch_row(res)))
{
for(int j=0;j {
printf("%s ",row[j]);
}
printf("\n");
}
if the MySQL query get a tuple whchi has field "NULL", then problem comes!

No comments: