Two WHEREs in a SQL Query?

Posted on 2004-10-27
Last Modified: 2010-05-18
I have a select statement where I need to have two WHERE conditions satisfied. What is the syntax for that?

Here's the statement I'm using -- it generates an "invalid syntax" error, probably due to my use of "and"...?

select * from [Auct-PMT] where EbayNum = 'Me.EbayNum.Value' and where [Date-Time] = 'Me.AuctionPmt_Subform![Date-Time]'

(This SQL code appears in one of my MS Access form events, hence the reference structure.)
Question by:Galisteo8
    LVL 8

    Accepted Solution

    remove second WHERE
    select * from [Auct-PMT] where EbayNum = 'Me.EbayNum.Value' and [Date-Time] = 'Me.AuctionPmt_Subform![Date-Time]'
    LVL 1

    Expert Comment

    Just drop the second WHERE... you simply separate the expressions with logical AND or OR operators.

    select * from [Auct-PMT] where EbayNum = 'Me.EbayNum.Value' and [Date-Time] = 'Me.AuctionPmt_Subform![Date-Time]'

    -- Brian
    LVL 8

    Author Comment

    <slapping forehead> Oh yeah!  Many thanks for answer as well as speed.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now