11
Creating Databases SQL joins. Miscellaneous. Work session. Homework: continue work on projects

Creating Databases

Embed Size (px)

DESCRIPTION

Creating Databases. SQL joins. Miscellaneous. Work session. Homework: continue work on projects. SQL join. SELECT statement against a table made up by JOINing tables together on identical fields. Different types of JOIN: JOIN (same as INNER JOIN) LEFT JOIN RIGHT JOIN FULL JOIN - PowerPoint PPT Presentation

Citation preview

Page 1: Creating Databases

Creating Databases

SQL joins. Miscellaneous.

Work session.

Homework: continue work on projects

Page 2: Creating Databases

SQL join

• SELECT statement against a table made up by JOINing tables together on identical fields.

• Different types of JOIN:– JOIN (same as INNER JOIN)– LEFT JOIN– RIGHT JOIN– FULL JOINhttp://www.w3schools.com/sql/sql_join.asp

Page 3: Creating Databases

SELECT Conditions

• WHERE – Sets condition on individual records

• with a JOIN – the ON specifying what field to do the JOIN

on, generally a foreign key equal to a primary key

• After aggregating using GROUP– HAVING sets a condition on grouped data

Page 4: Creating Databases

Conditions

• Remember: the single equal sign is the operator for equality!

• Other comparisons: >, <, >=, <=

• LOGIC: AND, OR, NOT

• REGEX for regular expressions

• LIKE: another way to specify a pattern

Page 5: Creating Databases

Conditions

• Can select using set of values

• SELECT * FROM questions WHERE category IN (‘trivia’,’misc’,’silly’)

• See also BETWEEN

Page 6: Creating Databases

UPDATE

• Can update a single record or a set of records.

• UPDATE questions SET text = ‘$ntext’ WHERE ques_id=‘$qid’– Assumes table names questions with fields

text and ques_id and php variables $ntext and $qid set previously

Page 7: Creating Databases

UPDATE

• Raise all the prices 10%– UPDATE products SET price=1.10*price

• Raise the prices that are over 100 by 5%– UPDATE products SET price=1.05*price

WHERE price > 100

Page 8: Creating Databases

Presentation projects

• Explain all the SELECT statements, original ones and any you add!

Page 9: Creating Databases

Ideas for enhancing basic projects• ALL projects:

– add edit facility• display records and allow changes of fields.• Determine if this requires changing records in another place.

– improve looks!– add different types of displays– add fields– add more data, that is, more records

• Trivia quiz: allow looser check for correctness• Songs, quiz, book marks: include suggested categories• Origami store: create scripts for displaying all orders• ???

Page 10: Creating Databases

Classwork

• Share ideas on enhancements

Page 11: Creating Databases

Classwork / homework

• Work on projects