Sql and Databases Flashcards
Select Statement in sql.
SELECT * from Tablename;
Select collumname,collumname2 from table name;
How to select distinct values
Select Distinct collumname from tablename;
what goes around a string when being matched
single quotes.
‘example’
How to specify Selection order?
Select * From Tablename orderby collumname asc/desc;
(can have multiple ordering if a comma seperates them)
Insertion of sql 2 methods
- Insert into tablename values(value1,value2,…..); (note: must have all table values)
- Insert Into tablename (collum1,collum2,…) values(value1,value2,…);
Updating a table
UPDATE tablename
SET column1=value1, collumn2=value2,….
where some-collumn=somevalue;
Deleting
Delete from tablename where somecolumn=somevalue;
(deletes a row)
What does the wildcard % mean
substtues for 0 or more characters.
what does the wildcard _ mean
substitutes for 1 character
what does the wildcard [] , and [^ } mean
sets range of character to match, or to not match (with ^)
Inner join
Returns the rows mentioned from multiple tables wher ethe condition is met.
Select collumnnames from table1 innerjoin table2 on t1.name=t2.name;
usuing a where instead of a innerjoin
Select collumnames from tablenames where table1.ID=table2.ID;
note all table names are listed
what is a union and unionall?
Union combines 2 or more select statements (only gets distrink values)
Unionall- the same but shows non distink values.
Select into
Copies data from one table into a new table.
Select collumnnames into newtable from table1;
(note if where 1=0 is used a new table of the same form is created with no data)
INsert into
Copies data from one table into an exisitng table.
Insert into table2 (collumname) select columnnames from table1;