The Queries in this page solved at the library database. It is a sample database generated by randomly records. You can download it from the link. You will see more than 500 examples in the future. You can filter from the search panel above by selecting sql statements. I hope you will like it

**Solution 1)**

```
Select * from students
where name =
```*'Bill'*

ETİKETLER

Select - Where -
**Solution 1)**

```
Select * from students
where name like 'a%'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from students
where name like '%a'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from students
where name like '%a%'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from books
where bookId like '%1%'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from students
where name like '_a%'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from students
where name like '%a_'
```

ETİKETLER

Select - Where - Like -
**Solution 1)**

```
Select * from students
where studentId<= 20 and studentId< 30
```

**Solution 2)**

```
Select * from students
where studentId between 20 and 30
```

ETİKETLER

Select - Where - Between - Multi Condition -
**Solution 1)**

```
select * from students
where name= 'James' and surname not like '%a%'
```

ETİKETLER

Select - Where - Like - Multi Condition -
**Solution 1)**

```
select *from students
where (name='Kane' or name= 'Jane') and studentId <30
```

**Solution 2)**

```
Select * from students
where name='Kane' and studentId <30 or name='Jane' and studentId <30
```

**Solution 3)**

```
select * from students
where name in('Kane','Jane') and studentId<30
```

ETİKETLER

Select - Where - Brackets - Multi Condition -
**Solution 1)**

```
Select * from books
where bookId in(3,4,8,9,11,23)
```

**Solution 2)**

```
Select * from books
where bookId = 3 or
bookId = 4 or
bookId = 8 or
bookId = 9 or
bookId =11 or
bookId = 23
```

ETİKETLER

Select - Where -
**Solution 1)**

```
Select * from books
where bookId % 2 = 0
```

ETİKETLER

Select - Where -
**Solution 1)**

```
select * from students
where name = 'Perez' and surname not like '%a%'
```

**Solution 2)**

```
select * from students
where name = 'Perez' and not surname like '%a%'
```

ETİKETLER

Select - Where - Multi Condition -
**Solution 1)**

```
select * from students
where ("Edwards" or "Baker") and studentId<30
```

**Solution 2)**

```
select * from students
where name='Edwards' and studentId<30 or
name='Baker' and studentId<30
```

ETİKETLER

Select - Where - Brackets - Multi Condition -
**Solution 1)**

```
select * from students
where studentId=1 or studentId=7 or
studentId=11 or studentId=17
```

**Solution 2)**

```
select * from student
where studentId in (1,7,11,17)
```

ETİKETLER

Select - Where -
**Solution 1)**

```
Select * from students
where studentId % 2 = 1
```

ETİKETLER

Select - Where -
**Solution 1)**

```
Select * from student
where name like 'a%' and studentId % 2 = 1
```

ETİKETLER

Select - Where - Multi Condition -
**Solution 1)**

```
Select * from students
where gender = 'M'
order by name
```

**Solution 2)**

```
Select * from students
where gender = 'M'
order by 2
```

ETİKETLER

Select - Where - Order By -
**Solution 1)**

```
Select * from students
where gender = 'M'
order by newid()
```

ETİKETLER

Select - Where - Order By -
**Solution 1)**

```
select * from students
where sinif='10A' and gender='M'
order by newid()
```

ETİKETLER

Select - Where - Order By -
**Solution 1)**

```
Select top 1 * from students
where sinif= '10A'
order by newid()
```

ETİKETLER

Select - Top - Where - Order By -
**Solution 1)**

```
Select top 1 * from students
where sinif= '10A' and gender= 'F'
order by newid()
```

ETİKETLER

Select - Top - Where - Order By - Multi Condition -
**Solution 1)**

```
Select top 1 * from books
order by sayfaSayisi desc
```

**Solution 2)**

```
Select * from books
where sayafaSayisi=(Select max(sayfaSayisi) from books)
```

ETİKETLER

Select - Top - Where - Order By - Sub Query - Aggragate -
**Solution 1)**

```
Insert into authors(name,surname)
select name,surname from students
where sinif='9A' and gender='M'
```

**Solution 2)**

```
Insert into authors
select name,surname from students
where sinif='9A' and gender='M'
```

ETİKETLER

Select - Insert - Where -
**Solution 1)**

```
Select name,surname,takenDate from students,borrows
where students.studentId = borrows.studentId
```

**Solution 2)**

```
Select name,surname,takenDate from students
join borrows on students.studentId = borrows.studentId
```

ETİKETLER

Select - Join - Where - Çoklu Tablo -
**Solution 1)**

```
Select students.name,students.surname,books.name,takenDate
from students,borrows,books
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId
```

**Solution 2)**

```
Select students.name,students.surname,books.name,takenDate from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
```

ETİKETLER

Select - Join - Where - Çoklu Tablo -
**Solution 1)**

```
Select students.name as OgrenciAd,
students.surname,books.name as KitapAd,
takenDate,types.name as TurAd
from students,borrows,books,types
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and
books.typeId = types.typeId
```

**Solution 2)**

```
Select students.name as studentName,
students.surname,books.name as BookName,
takenDate,types.name as TypeName
from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
join types on books.typeId = types.typeId
```

ETİKETLER

Select - Join - Where - Çoklu Tablo -
**Solution 1)**

```
Select students.name as studentName,
students.surname,books.name as BookName,
takenDate,types.name as TypeName,
authors.name as AuthorName, authors.surname as AuthorSurname
from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
join types on books.typeId = types.typeId
join authors on authors.authorId = books.authorId
```

**Solution 2)**

```
Select students.name as studentName,students.surname,
books.name as BookName,takenDate,types.name as TypeName ,
authors.name as AuthorName,authors.surname as AuthorSurname
from students, borrows, books, types, authors
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and
books.typeId = types.typeId and
authors.authorId = books.authorId
```

ETİKETLER

Select - Join - Where - Çoklu Tablo -
**Solution 1)**

```
Select students.name as studentName,students.surname,
books.name as BookName,takenDate
from students,borrows,books,types,authors
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and sinif='11B'
```

**Solution 2)**

```
Select students.name as studentName,students.surname,
books.name as BookName,takenDate
from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
where sinif='11B'
```

ETİKETLER

Select - Join - Where - Çoklu Tablo -
**Solution 1)**

```
Select students.name as studentName,students.surname,
books.name as BookName,takenDate
from students, borrows, books, types, authors
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and
sinif='11B' and gender='F'
```

**Solution 2)**

```
Select students.name as studentName,students.surname,
books.name as BookName,takenDate
from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
where sinif='11B' and gender='F'
```

ETİKETLER

Select - Join - Where - Multi Condition - Çoklu Tablo -
**Solution 1)**

```
Select authors.name, authors.surname, books.name as bookName from authors
join books on authors.authorId = books.authorId
join types on types.typeId = books.typeId
where types.name = 'Drama'
```

**Solution 2)**

```
Select authors.name, authors.surname, books.name as bookName
from authors, books, types
where authors.authorId = books.authorId and
types.typeId = books.typeId and
types.name = 'Drama'
```

ETİKETLER

Select - Join - Where - Multi Condition - Çoklu Tablo -
**Solution 1)**

```
Select books.name as bookName, authors.name, authors.surname
from authors
join books on authors.authorId = books.authorId
where pagecount >300
```

**Solution 2)**

```
Select authors.name, authors.surname, books.name as bookName
from authors,books
where authors.authorId = books.authorId and pagecount >300
```

ETİKETLER

Select - Join - Where - Multi Condition - Çoklu Tablo -
**Solution 1)**

```
Select distinct students.* from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
join authors on authors.authorId = books.authorId
where authors.name = 'Isaac' and authors.surname = 'Asimov'
```

**Solution 2)**

```
Select distinct students.*
from students, borrows, books, authors
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and
authors.authorId = books.authorId and
authors.name = 'Isaac' and authors.surname = 'Asimov'
```

ETİKETLER

Select - Join - Where - Multi Condition - Çoklu Tablo -
**Solution 1)**

```
Select distinct students.* from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
join authors on authors.authorId = books.authorId
where authors.name = 'Fyodor' and authors.surname = 'Dostoevsky' and sinif = '10A'
```

**Solution 2)**

```
Select distinct students.*
from students, borrows, books, authors
where students.studentId = borrows.studentId and
books.bookId = borrows.bookId and
authors.authorId = books.authorId and
authors.name = 'Fyodor' and authors.surname = 'Dostoevsky' and
sinif = '10A'
```

ETİKETLER

Select - Join - Where - Multi Condition - Sub Query - Çoklu Tablo -
**Solution 1)**

```
Select count(*) from students
where sinif = '9B'
```

ETİKETLER

Select - Where - Aggragate -
**Solution 1)**

```
Select sum(pageCount) from books
join types on types.typeId = books.typeId
where types.name = 'Romance'
```

ETİKETLER

Select - Join - Where - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select count(*) from books
join types on types.typeId = books.typeId
where types.name = 'Horror'
```

ETİKETLER

Select - Join - Where - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select avg(pageCount) from books
join types on types.typeId = books.typeId
where types.name = 'Comics'
```

ETİKETLER

Select - Join - Where - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select sum(pageCount) from books
join authors on authors.authorId = books.authorId
where authors.name = 'John' and authors.surname = 'DosPassos'
```

ETİKETLER

Select - Join - Where - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select sum(point) from books
join authors on authors.authorId = books.authorId
where authors.name = 'Emily' and authors.surname = 'Dickinson'
```

ETİKETLER

Select - Join - Where - Multi Condition - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select count(*) from books
join authors on authors.authorId = books.authorId
where authors.name = 'Edna' and authors.surname = 'Ferber'
```

ETİKETLER

Select - Join - Where - Multi Condition - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select count(*) from students
join borrows on students.studentId = borrows.studentId
where students.name = 'Alice' and students.surname = 'Wood'
```

ETİKETLER

Select - Join - Where - Multi Condition - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select sum(pageCount) from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
where students.name = 'Ainsley' and students.surname = 'Cooper'
```

ETİKETLER

Select - Join - Where - Multi Condition - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Select count(distinct authorId) from students
join borrows on students.studentId = borrows.studentId
join books on books.bookId = borrows.bookId
where students.name = 'Ida' and students.surname = 'Gray'
```

ETİKETLER

Select - Distinct - Join - Where - Multi Condition - Aggragate - Çoklu Tablo -
**Solution 1)**

```
Insert into students(name,surname,sinif)
Select name,surname,'12M' from authors where name like '%a%'
```

ETİKETLER

Select - Insert - Where -
**Solution 1)**

```
Select top 1 students.*,takendate
from students,borrows
where students.studentId = borrows.studentId
order by borrows.takenDate desc
```

**Solution 2)**

```
Select top 1 students.*,takendate
from students
join borrows on students.studentId = borrows.studentId
order by borrows.takenDate desc
```

**Solution 3)**

```
Select students.*,takendate
from students
join borrows on students.studentId = borrows.studentId
where takenDate = (Select max(takenDate) from borrows)
```

ETİKETLER

Select - Top - Join - Where - Order By - Sub Query - Çoklu Tablo -
**Solution 1)**

```
Select sinif,gender,count(*) as StudentCount
from students
where gender = 'F'
group by gender,sinif
```

ETİKETLER

Select - Where - Group By - Aggragate - Alias -
**Solution 1)**

```
Select name,surname,count(*) BookCount
from students,borrows
where students.studentId = borrows.studentId
group by students.studentId,name,surname
```

**Solution 2)**

```
Select name,surname,count(*) BookCount
from students
join borrows on students.studentId = borrows.studentId
group by students.studentId,name,surname
```

ETİKETLER

Select - Join - Where - Group By - Aggragate - Alias - Çoklu Tablo -
**Solution 1)**

```
Select name,surname,count(*) BookCount
from students
join borrows on students.studentId = borrows.studentId
group by students.studentId,name,surname
order by BookCount desc
```

**Solution 2)**

```
Select name,surname,count(*) BookCount
from students,borrows
where students.studentId = borrows.studentId
group by students.studentId,name,surname
order by BookCount desc
```

ETİKETLER

Select - Join - Where - Group By - Order By - Aggragate - Alias - Çoklu Tablo -
**Solution 1)**

```
Select name,surname,count(borrowsno) BookCount
from students
left join borrows on students.studentId = borrows.studentId
group by students.studentId,name,surname
order by BookCount
```

**Solution 2)**

```
Select name, surname,
(Select count(*) from borrows
where students.studentId = borrows.studentId) as BookCount
from students
order by BookCount
```

ETİKETLER

Select - Top - Where - Having - Sub Query -
**Solution 1)**

```
Select students.* from students
left join borrows on students.studentId = borrows.studentId
where borrowsno is null
```

**Solution 2)**

```
Select * from students
where studentId not in
(Select studentId from borrows)
```

ETİKETLER

Select - Where - Sub Query - Çoklu Tablo - Left Join -
**Solution 1)**

```
Select books.* from books
left join borrows on books.bookId = borrows.bookId
where borrowsno is null
```

**Solution 2)**

```
Select * from books
where bookId not in
(Select bookId from borrows)
```

ETİKETLER

Select - Where - Sub Query - Çoklu Tablo - Left Join -Library Database