Answer the question
In order to leave comments, you need to log in
Sampling from two microsoft sql 2008 tables?
There are two tables:
USERS (id, email) a table of users with email
USER_SERVICE_PAYMENT (id, user_service_id) a table indicating the date of access to a particular section on the site
You need to select users from the USER_SERVICE_PAYMENT table with access to section 1 with an access period from 01.05 .2014 until 12/31/2100 at the same time see the e-mails of the user data.
select * from USER_SERVICE_PAYMENT
where USER_SERVICE_ID = '1' and paid_until between '2014-05-01' and '2100-12-31'
SELECT *
FROM USER_SERVICE_PAYMENT as A
INNER JOIN USERS as B ON (A.USER_SERVICE_ID = B.EMAIL)
WHERE A.USER_SERVICE_ID = '1' and paid_until between '2014-05-01' and '2100-12-31' and EMAIL = 'NULL'
Answer the question
In order to leave comments, you need to log in
If USER_SERVICE_ID is a userid (same as id in USERS), then something like this:
SELECT *
FROM USER_SERVICE_PAYMENT as A
INNER JOIN USERS as B ON (A.USER_SERVICE_ID = B.ID)
WHERE A.USER_SERVICE_ID = '1' and paid_until between '2014-05-01' and '2100-12-31'
I'm not a specialist in MSCL, but I think you're joining id with email, so you can't. you need to join by the column by which these tables define the user, like user_id in one table = 5, in the second table the same ID is taken and joined to the resulting selection
SELECT *
FROM USER_SERVICE_PAYMENT as A
INNER JOIN USERS as B ON (A.USER_SERVICE_ID = B.USER_ID)
WHERE A.USER_SERVICE_ID = '1' and A.paid_until between '2014-05-01' and '2100-12-31'
INNER JOIN USERS as B ON (A.USER_SERVICE_ID = B.USER_ID)
SELECT *
FROM USER_SERVICE_PAYMENT as A
INNER JOIN USERS as B ON (A.ID = B.USER_ID)
WHERE A.USER_SERVICE_ID = '1' and A.paid_until between '2014-05-01' and '2100-12-31'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question