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

  • SEARCH
  • Home
  • 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 633993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:14:45+00:00 2026-05-13T20:14:45+00:00

Im trying to get this query to work but i get this error: Unknown

  • 0

Im trying to get this query to work but i get this error:
Unknown column ‘zips.city’ in ‘having clause’

`$query = "SELECT
    zips.*
    FROM
    zips
    HAVING
    zips.city LIKE '%$city%' 
    AND
    zips.stateabbr LIKE '%$state%' 
    LIMIT 1";
$result = mysql_query($query) or die (mysql_error());`

my zips table has a city column, so im not sure what the problem is, i know im accessing the database because i can run this query with no errors:

$zip1query = "SELECT 
         zips.*
         FROM 
         zips
         WHERE
         zips.zip = '$zip'              
         ";

any advice would be much appreciated! thanks!

  • 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-13T20:14:46+00:00Added an answer on May 13, 2026 at 8:14 pm

    The having clause doesn’t mean the same thing as the where clause : when running a simple query, you should use where — which is what you did in your second query, that works.

    having is used when the condition has to be applied on the result of a group by clause.

    Which means that, here, your query should be build this way :

    $query = "SELECT zips.*
        FROM zips
        where zips.city LIKE '%$city%' 
            AND zips.stateabbr LIKE '%$state%' 
        LIMIT 1";
    

    With that, if you still have an error about a non-existing or not-found column (at least for city and/or stateabbr), it’ll be because that column doesn’t exist in your table.

    In this case, there is not much we can do : you’ll have to check the structure of your table, to determine which columns it contains.

    You can check that structure using a web-based tool like phpMyAdmin, or using an SQL instruction such as :

    desc zips;
    

    For reference, quoting MySQL’s manual page for select :

    The SQL standard requires that HAVING
    must reference only columns in the
    GROUP BY clause or columns used in
    aggregate functions.
    …

    Do not use HAVING for items that
    should be in the WHERE clause.

    For example, do not write the
    following:

    SELECT col_name FROM tbl_name HAVING col_name > 0;
    

    Write this instead:

    SELECT col_name FROM tbl_name WHERE col_name > 0;
    

    …

    The HAVING clause can refer to
    aggregate functions, which the WHERE
    clause cannot

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do this query INSERT INTO dbo.tbl_A_archive SELECT * FROM SERVER0031.DB.dbo.tbl_A but
I'm trying to get this to work, but I am having issues. What am
I'm trying to get this query to work in CodeIgniter but it's spitting out
I am trying to deserialize a stream but I always get this error End
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm trying to get this simple PowerShell script working, but I think something is
I've been trying to get this code to work for hours! All I need
hI, I'm trying to get this code from Larry Nyhoff's book to compile in
I have been trying to get around this error for a day now and
I get this error: System.Reflection.TargetException: Object does not match target type. when trying to

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.