{"base":{"id":"cs9-21","subject":"Data","title":"Queries with several conditions","scene":"data9","steps":[{"mode":"andor","eyebrow":"AND and OR","title":"Both, or either?","body":"A query finds records that match conditions. With AND, both must be true; with OR, either is enough. Change the year and rating and switch between AND and OR.","controls":[{"id":"year","label":"Published after","min":2010,"max":2022,"step":1,"value":2018},{"id":"rating","label":"Rating at least","min":1,"max":5,"step":1,"value":4}],"actions":[{"id":"and","label":"AND"},{"id":"or","label":"OR"}]},{"mode":"join","eyebrow":"Across two tables","title":"JOIN, then filter","body":"Which students scored highly in Science? Names are in one table and scores in another. The query joins them on StudentID, then filters. Change the minimum score.","controls":[{"id":"min","label":"Minimum score","min":50,"max":95,"step":5,"value":70}]},{"mode":"qtext","eyebrow":"Write the query","title":"From words to conditions","body":"Each part of a question becomes a condition. Look at three questions and their WHERE clauses.","actions":[{"id":"q0","label":"Question 1"},{"id":"q1","label":"Question 2"},{"id":"q2","label":"Question 3"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"AND or OR?","body":"You want films that are both a comedy and shorter than 100 minutes.","question":"Which condition is right?","options":["Genre = \"comedy\" AND Length < 100","Genre = \"comedy\" OR Length < 100","Length < 100"],"answer":0,"right":"Correct. Both conditions must be true, so use AND.","wrong":"Not quite. Both, or either?","look":"andor"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"OR gives fewer results than AND.\"","body":"OR usually gives more: a record only needs to match one condition."},{"tag":"Popular idea","title":"\"You can only search one table at a time.\"","body":"A JOIN combines related tables using their keys."},{"tag":"Popular idea","title":"\"Genre = mystery OR science finds both.\"","body":"Write each condition in full: Genre = \"mystery\" OR Genre = \"science\"."}]},{"type":"cards","id":"code","eyebrow":"Queries","title":"Examples","items":[{"tag":"AND","title":"Both true","body":"WHERE Year > 2018 AND Rating >= 4","code":true},{"tag":"OR","title":"Either true","body":"WHERE Genre = \"science\" OR Genre = \"adventure\"","code":true},{"tag":"JOIN","title":"Two tables","body":"SELECT Name, Score\nFROM Students JOIN Results\nON Students.StudentID = Results.StudentID\nWHERE Score >= 70","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Card query","items":[{"title":"Query a deck","time":"15 minutes","need":["A pack of cards"],"steps":["Query 1: red AND higher than 7. Pull out the matching cards.","Query 2: red OR higher than 7.","Count the cards each time.","Write a query that returns exactly 4 cards."],"why":"AND narrows a search; OR widens it.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"Which gives more results, usually?","options":["AND","Always the same","OR"],"answer":2,"right":"Correct. One condition is enough with OR.","wrong":"Not quite. Either vs both."},{"question":"Price < 10 AND colour = \"blue\". A red item costing $5 is…","options":["not returned","returned","an error"],"answer":0,"right":"Correct. Colour fails.","wrong":"Not quite. Both must be true."},{"question":"Price < 10 OR colour = \"blue\". A red item costing $5 is…","options":["not returned","an error","returned"],"answer":2,"right":"Correct. Price matches.","wrong":"Not quite. Only one needed."},{"question":"Why JOIN two tables?","options":["To delete data","To sort data","To use fields from both"],"answer":2,"right":"Correct. Combine related data.","wrong":"Not quite. Data in two places."},{"question":"Which field normally links Students and Results?","options":["Score","StudentID","Subject"],"answer":1,"right":"Correct. The shared key.","wrong":"Not quite. The key."},{"question":"Find books from 2020 or later with 5 stars. Which is right?","options":["Year >= 2020 OR Rating = 5","Year >= 2020 AND Rating = 5","Year > 2020 AND Rating > 5"],"answer":1,"right":"Correct. Both conditions; 2020 included.","wrong":"Not quite. Include 2020, both conditions."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how AND and OR change the results of a query","how to write conditions from a question","why a query may need two tables","how a JOIN uses keys"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"query","meaning":"A request for data that matches conditions."},{"word":"condition","meaning":"A test such as Year > 2018."},{"word":"AND","meaning":"Both conditions must be true."},{"word":"OR","meaning":"At least one condition must be true."},{"word":"JOIN","meaning":"Combining related tables in a query."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}