Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
9012445   
9012332

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
add comment

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.

1 Answer

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
FROM a
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
add comment

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