ORDER BY ক্লজের সাথে IFNULL() ফাংশন ব্যবহার করে NULL মানযুক্ত কলামের পরিবর্তে অন্য কলাম দিয়ে সর্ট করা যায়। সিনট্যাক্স:
SELECT *FROM yourTableName ORDER BY IFNULL(yourColumnName1, yourColumnName2);
উদাহরণ
টেবিল IfNullDemo তৈরি (ProductWholePrice এবং ProductRetailPrice কলামে NULL রয়েছে)।
কোয়েরি: ProductWholePrice NULL হলে ProductRetailPrice দিয়ে সর্ট করো।
mysql> select *from IfNullDemo order by ifnull(ProductWholePrice,ProductRetailPrice);
ফলাফল (NULL গুলো শেষে, তারপর মান অনুযায়ী সর্টেড):
+----+-------------+-------------------+--------------------+ | Id | ProductName | ProductWholePrice | ProductRetailPrice | +----+-------------+-------------------+--------------------+ | 4 | Product-4 | NULL | NULL | | 2 | Product-2 | NULL | 76.56 | | 1 | Product-1 | 99.5 | 150.5 | | 3 | Product-3 | 105.4 | NULL | | 5 | Product-5 | 209.9 | 400.5 | +----+-------------+-------------------+--------------------+