Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to try querying two tables, like this:

Table A

user_id   primary_indicator
-------   -----------------
9012445   Y
9012445   N
9012442   N
9012332   Y
9012332   N

Table B

access_id user_id
--------- -------
00014359  9012445
00014323  9012442
02349995  9012332

I want to get access_id where primary_indicator in table A is 'N'.

How can I do this?

share|improve this question

closed as off topic by Leigh Riffel, dezso, RolandoMySQLDBA, Mark Storey-Smith, ypercubeᵀᴹ Jan 31 '13 at 13:19

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I'm not sure what you mean by your final sentence:

as what i tried, i cannot get a clear access_id where primary_indicator is 'N' can u help me

Doesn't it work just to do it like this?

SELECT b.access_id
JOIN b ON a.user_id = b.user_id
WHERE a.primary_indicator = 'N'

If that's what you're looking for, you should read up on the subject of JOINS, as they're fundamental to querying multiple tables at once.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.