MySQL sorting help

GT9

Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    මචංල මගේ මට ටේබල් එකක තියෙන field එකක් sort කරන්න ඕන asc and desc විදියට. ඒක වැඩ කරනව. නමුත් පොඩි අවුලක් තියෙනව asc sorting එකේදී. අදාල column එකේ තියෙන null values උඩින්ම පෙන්නනව. මට ඕන null පස්සේ පෙන්නන්න. desc වලදි නම් අවුලක් නෑ. මම ISNULL වගේ එක එක ක්‍ර‍ම ට්‍ර‍යි කරා. සමහර ක්‍ර‍ම වලින් NULL ටික යටට දාගත්තට. SORTING ORDER එක වැරදියට එන්නේ. :dull: ඔය ෆීල්ඩ් එකේ තියෙන්‍ෙ. මෙම්බර්ගේ නම. :confused:

    මේක කරන විදියක් කියල දෙන්න sorting order එක අවුල් යන්නේ නැති. :D
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    Google karala baluwada ?
    Thread ekak danawata wada eka lesi banhttps://www.google.lk/search?q=mysql+order+by+asc+null+last

    ගූගල් කරා පැය ගානක්. ඒ හැම දේම කරල බැලුව. Null ටික පස්සට දාගන්න පුලුවන්. නමුත් sorting වැරිදියට වෙන්නේ.


    මේකත් මම බැලුව මචං. :D
     

    AnuradhaRa

    Well-known member
  • Dec 25, 2010
    61,406
    1
    42,483
    113
    MS Access කියන්නේ වෙනම database ජාතියක් බන්. MySQL වලින් කරන්න ඕන ඩේ access වලින් කරලා හරියන්නේ නැ

    :P
     

    Yahapala_Naya

    Member
    Apr 10, 2015
    2,223
    180
    0
    ගෙදර
    http://stackoverflow.com/questions/5993109/order-by-asc-with-nulls-at-the-bottom

    original query

    SELECT
    schools.id AS schoolid,
    schools.name AS school,
    districts.id AS districtid,
    districts.name AS district
    FROM sms_schools AS schools
    LEFT JOIN sms_districts AS districts ON schools.districtid = districts.id
    WHERE 1 = 1
    ORDER BY districts.name, schools.name


    fix
    ORDER BY (CASE WHEN districts.id IS NULL then 1 ELSE 0 END),districts.name, schools.name;
     

    thinking_guy

    Well-known member
  • Apr 16, 2011
    4,718
    2,737
    113
    Mehema karala balapan. Tabele eka t1, umbata sort karanna ona filed eka f1 kiyala hitamau.

    SELECT * FROM t1 ORDER BY IIF(ISNULL(f1),1,0) ASC, f1 ASC/DSC
     
    Last edited:

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    http://stackoverflow.com/questions/5993109/order-by-asc-with-nulls-at-the-bottom

    original query

    SELECT
    schools.id AS schoolid,
    schools.name AS school,
    districts.id AS districtid,
    districts.name AS district
    FROM sms_schools AS schools
    LEFT JOIN sms_districts AS districts ON schools.districtid = districts.id
    WHERE 1 = 1
    ORDER BY districts.name, schools.name


    fix
    ORDER BY (CASE WHEN districts.id IS NULL then 1 ELSE 0 END),districts.name, schools.name;

    Mehema karala balapan. Tabele eka t1, umbata sort karanna ona filed eka f1 kiyala hitamau.

    SELECT * FROM t1 ORDER BY IIF(ISNULL(f1),1,0) ASC, f1 ASC/DSC

    මචංල මේ ආකාරයට කරාම Null ටික පහලට දාගත්තතට. sorting වරදිනව එතකොට. :(
     

    thinking_guy

    Well-known member
  • Apr 16, 2011
    4,718
    2,737
    113
    මචංල මේ ආකාරයට කරාම Null ටික පහලට දාගත්තතට. sorting වරදිනව එතකොට. :(

    Mewidiyata Null pahalata dagena ayeth e field ekama 2nd order ekata sort karapan.

    IIF(ISNULL(f1),1,0) ASC, f1 ASC/DSC
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]


    Mewidiyata Null pahalata dagena ayeth e field ekama 2nd order ekata sort karapan.

    IIF(ISNULL(f1),1,0) ASC, f1 ASC/DSC

    වැඩ කරන්නෑ මචං. :no: IIF එක මම IF කරලත් බලුව මම USE කරන්නේ MYSQL නිසා. ඒත් වැඩ නෑ. :dull: