Problem with Using the AND Condition

In the WHERE condition, I have not been able to use the AND condition when the two conditions on either side of the AND command relate to data the same column.

For instance, print out all trips made to New York and San Francisco. The query returns blank data.

Can you help me?

As you haven’t attached the actual SQL you are using, I will have to make an educated guess based on your question.

Let’s assume that you have a table named “trips” with a field called “destination.” It sounds like you might have literally translated your English statement into something like this:

select * from tripswheredestination = 'NEW YORK'  anddestination = 'SAN FRANCISCO'

However, SQL follows the rules of Boolean logic, not English. The above statement actually tells the server only to return rows where the destination is ‘NEW YORK’ and ‘SAN FRANCISCO’. That is an impossibility.

Instead, rephrase your request as such. You want to return all rows where the destination is either ‘NEW YORK’ or ‘SAN FRANCISCO’. In SQL that would be:

select * from trips wheredestination = 'NEW YORK' ordestination = 'SAN FRANCISCO'

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may