Sorry for the entry-level database question but I really want to learn this.
I have two tables customer_change and customer_full and I want to select rows from customer_full that same customer(same customer_id) but with different customer_points.
I wrote the following query:
SELECT *
FROM customer_change a,customer_full b
WHERE
a.ID = b.ID AND
a.CUSTOMER_POINTS != b.CUSTOMER_POINTS
Now it works. But it will return rows in both tables, how could I change the query to only return the rows in the second table?
Also, the returned rows may contain two rows that have the same IDs, could I modify my query to only include the first row that has this ID?
Could experts offer some help? Thanks!
The SQL inequality operator is
<>, not!=. (Apologies: I note that!=is supported in at least some implementations! As the comments on the question have pointed out, it seems to be a character set problem. I stand by the rest of my answer, though. :))That said, I recommend learning about JOIN syntax, rather than joining tables using WHERE criteria. The former lends itself to more-readable queries, and lets you exercise finer control over how the tables are joined.
For example, your query above would be: