Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:36:24+00:00 2026-05-23T22:36:24+00:00

i have this query that works fine SELECT t.username FROM users t LEFT JOIN

  • 0

i have this query that works fine

SELECT t.username
FROM users t LEFT JOIN friends y ON t.id=y.user_id2 and y.user_id1=2
WHERE LOWER(t.username) LIKE 'ha%'
ORDER BY 
    CASE WHEN y.user_id2 IS NULL THEN 1 
    ELSE 0 
    END     
    ,t.username;

i’m trying to write it with zend framework and this is what i came up with

        $users = new Users;
        $select = $users->select();
        $select->setIntegrityCheck(false);
        $select->from(array('t1' => 'users'), array('username'));
        $select->joinLeft(array('t2' => 'friends'), 't1.id=t2.user_id2 and t2.user_id1 =2');
        $select->where("LOWER(t1.username) like '$input%'");
        $select->order("t1.username, CASE WHEN t2.user_id2 IS NULL THEN 1 ELSE 0 END ");
        $listofusernames = $users->fetchAll($select);

however it seems not to work and i get this error

Fatal error: Uncaught exception 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Unknown column 't1.username, CASE WHEN t2.user_id2 IS NULL THEN 1 ELSE 0 END ' in 'order clause'' in /opt/lampp/htdocs/vote_old/library/Zend/Db/Statement/Mysqli.php:77 Stack trace: #0

apparently it has to do with the case embedded in the order by clause.

do you have any idea how to fix that code ?

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:36:24+00:00Added an answer on May 23, 2026 at 10:36 pm

    try to put the columns in array like

    $select->order(array('t1.username',
                  new Zend_Db_Expr ('CASE WHEN t2.user_id2 IS NULL THEN 1 ELSE 0 END')));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an html5 query that works fine like this: tx.executeSql('SELECT * FROM bdreminders
I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have this query: <?php $query= SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE
this query works fine using the php_mssql driver: INSERT INTO Table(columnName) VALUES ('text'); SELECT
SELECT u.username, count(t.tid) as total FROM tbl2 t JOIN users u ON t.userid =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.