We help IT Professionals succeed at work.

How to explain a not very complex query to an SQL beginner

288 Views
Last Modified: 2012-05-11
Consider the following:

item_categories
(item_id int(11),
 category_id int(11)
)

category_relations
(category1_id int(11),
  category2_id int(11),
  relation varchar(20)
)

Then we have the query that uses item1_id and item2_id as inputs:

select cr.relation
from category_relations cr, item_categories ic1, item_categories ic2
where ic1.item_id=item1_id
and ic2.item_id=item2_id
and cr.category1_id=ic1.category_id
and cr.category2_id=ic2.category_id;

How would you best explain the need for calling item_categories twice to an SQL beginner?  Things like this has become pretty second-nature to me, but having to explain it in simple terms suddenly got me stumped.  Thanks.
Comment
Watch Question

Senior Data Architect
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2012

Author

Commented:
Clear enough!  Thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.