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 7843593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:35:30+00:00 2026-06-02T16:35:30+00:00

I have a database consisting of a Customer, Product, and Transaction table. I’m trying

  • 0

I have a database consisting of a Customer, Product, and Transaction table.

I’m trying to write an SQL statement to list all customers’ names and SSN’s for those customers who have made no transaction in the year 2000.

The TransactionDate column in the Transaction table is a Date/Time data type (e.g. 2000-12-18 00:00:00).

This is the SQL code I’ve written:

SELECT DISTINCT CustomerName, Customer.CustomerSSN 
FROM Customer, Transaction
WHERE Customer.CustomerSSN=Transaction.CustomerSSN
AND YEAR(TransactionDate)<>2000;

The not equal to symbol (<>) seems to not be working for some reason. When I change it to an equal sign, it does return the correct result…

Any advice is appreciated.

  • 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-06-02T16:35:37+00:00Added an answer on June 2, 2026 at 4:35 pm

    I’d change the approach.

    The following query doesn’t need distinct or GROUP BY because none of the customer records are joined to multiple transaction records.

    It also works for customers who have never made Any transactions.

    Finally, it uses >= AND < rather than YEAR()=2000. This enable an index seek rather than a full scan (assuming that you have an approriate index on the transactions table).

    SELECT
      CustomerName,
      CustomerSSN
    FROM
      Customer
    WHERE
      NOT EXISTS (
        SELECT *
          FROM Transaction
         WHERE CustomerSSN      = Customer.CustomerSSN
           AND TransactionDate >= '20000101'
           AND TransactionDate <  '20010101'
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Sqlite database that has a table consisting of company information (Companies)
I have a table consisting 10 columns in database. One of the columns have
I have a database table consisting of countries. In my DAO which extends HibernateDAOSupport
I have a mysqldump backup of my mysql database consisting of all of our
Scenario I have a database consisting of a table called Problems which in turn
I have a database table consisting of strings... I need to search for a
I have the following database table consisting of a series of tasks: id BIGINT
I have a table in SQL Server 2008 R2 consisting of about 400 rows
I have database with multiple tables in Microsoft SQL Server with schema in tables
i have database table like this +-------+--------------+----------+ | id | ip | date |

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.