Showing posts with label Presentation. Show all posts
Showing posts with label Presentation. Show all posts

Wednesday, 24 August 2016

Understanding JOINs in MySQL and Other Relational Databases

“JOIN” is an SQL keyword used to query data from two or more related tables. Unfortunately, the concept is regularly explained using abstract terms or differs between database systems. It often confuses me. Developers cope with enough confusion, so this is my attempt to explain JOINs briefly and succinctly to myself and anyone who’s interested.

Related Tables

MySQL, PostgreSQL, Firebird, SQLite, SQL Server and Oracle are relational database systems. A well-designed database will provide a number of tables containing related data. A very simple example would be users (students) and course enrollments:

‘user’ table:

MySQL table creation code:
CREATE TABLE `user` (
                `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
                `name` varchar(30) NOT NULL,
                `course` smallint(5) unsigned DEFAULT NULL,
                PRIMARY KEY (`id`)
) ENGINE=InnoDB;

 

id
name
course
1
Alice
1
2
Bob
1
3
Caroline
2
4
David
5
5
Emma
(NULL)

The course number relates to a subject being taken in a course table…

‘course’ table:

MySQL table creation code:

CREATE TABLE `course` (
                `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
                `name` varchar(50) NOT NULL,
                PRIMARY KEY (`id`)
) ENGINE=InnoDB;
id
name
1
HTML5
2
CSS3
3
JavaScript
4
PHP
5
MySQL
Since we’re using InnoDB tables and know that user.course and course.id are related, we can specify a foreign key relationship:
ALTER TABLE `user`
ADD CONSTRAINT `FK_course`
FOREIGN KEY (`course`) REFERENCES `course` (`id`)
ON UPDATE CASCADE;
In essence, MySQL will automatically:
·         re-number the associated entries in the user.course column if the course.id changes
·         reject any attempt to delete a course where users are enrolled.
Important: This is terrible database design!
This database is not efficient. It’s fine for this example, but a student can only be enrolled on zero or one course. A real system would need to overcome this restriction — probably using an intermediate ‘enrollment’ table which mapped any number of students to any number of courses.
JOINs allow us to query this data in a number of ways.

INNER JOIN (or just JOIN)

The most frequently used clause is INNER JOIN. This produces a set of records which match in both the user and course tables, i.e. all users who are enrolled on a course:
SELECT user.name, course.name
FROM `user`
INNER JOIN `course` on user.course = course.id;
Result:
user.name
course.name
Alice
HTML5
Bob
HTML5
Carline
CSS3
David
MySQL

LEFT JOIN

What if we require a list of all students and their courses even if they’re not enrolled on one? A LEFT JOIN produces a set of records which matches every entry in the left table (user) regardless of any matching entry in the right table (course):
SELECT user.name, course.name
FROM `user`
LEFT JOIN `course` on user.course = course.id;
Result:
user.name
course.name
Alice
HTML5
Bob
HTML5
Carline
CSS3
David
MySQL
Emma
(NULL)

 

RIGHT JOIN

Perhaps we require a list all courses and students even if no one has been enrolled? A RIGHT JOIN produces a set of records which matches every entry in the right table (course) regardless of any matching entry in the left table (user):
SELECT user.name, course.name
FROM `user`
RIGHT JOIN `course` on user.course = course.id;

Result:
user.name
course.name
Alice
HTML5
Bob
HTML5
Carline
CSS3
(NULL)
JavaScript
(NULL)
PHP
David
MySQL
RIGHT JOINs are rarely used since you can express the same result using a LEFT JOIN. This can be more efficient and quicker for the database to parse:
SELECT user.name, course.name
FROM `course`
LEFT JOIN `user` on user.course = course.id;
We could, for example, count the number of students enrolled on each course:
SELECT course.name, COUNT(user.name)
FROM `course`
LEFT JOIN `user` ON user.course = course.id
GROUP BY course.id;
Result:
course.name
count()
HTML5
2
CSS3
1
JavaScript
0
PHP
0
MySQL
1

OUTER JOIN (or FULL OUTER JOIN)

Our last option is the OUTER JOIN which returns all records in both tables regardless of any match. Where no match exists, the missing side will contain NULL.
OUTER JOIN is less useful than INNER, LEFT or RIGHT and it’s not implemented in MySQL. However, you can work around this restriction using the UNION of a LEFT and RIGHT JOIN, e.g.
SELECT user.name, course.name
FROM `user`
LEFT JOIN `course` on user.course = course.id
UNION
SELECT user.name, course.name
FROM `user`
RIGHT JOIN `course` on user.course = course.id;


Result:
user.name
course.name
Alice
HTML5
Bob
HTML5
Carline
CSS3
David
MySQL
Emma
(NULL)
(NULL)
JavaScript
(NULL)
PHP
I hope that gives you a better understanding of JOINs and helps you write more efficient SQL queries.

Monday, 12 May 2014

Interview Tips for freshers

Interview Tips

Your CV shows that you have the skills and experience to do the job. Now you have the opportunity to persuade your potential future employer in person.

Preparation for Interview

Ensure you have made a note of the time and place of the interview, along with the name of your interviewer(s).

We will provide you with as much information as we can, but you are well advised to seek out anything you can about the company.  Go to your nearest reference library, look on the Internet, read the trade press or contact people you know in the industry.

Make a list of possible questions you may be asked and prepare your answers.

  • Strengths and weaknesses.
  • Breakdown of specific duties in your current role.
  • Notable achievements - personal and work related.
  • Reasons for leaving your current position.
  • Aspects of the job that appeal to you most.
  • Where you see yourself in five years time.

Be prepared to ask questions at the interview. The company will want to know that you are interested in the opportunity they are offering.


  • What goals do the company have?
  • Where do they expect to be in five years time?
  • How will this role develop?
  • Who are the company's direct competitors? 

Try to be original - discuss points raised in their brochure or in editorial you may have read about them.



Presentation 

First impressions do count, especially if your position involves a degree of face to face communication with management. Take time to get your best suit dry cleaned and make sure your shoes are clean and your hair is tidy. Remember, you never get a second chance to make a first impression!

You can easily search the site to find a suitable position from our selected Finance Manager Jobs or if you are looking for Audit Jobs, Alexander Lloyd, one of the most successful recruitment agencies in Crawley, will help you find the right position.



The Interview


  • Under no circumstances should you arrive late. Plan your journey in advance and give yourself plenty of time to overcome the hazards of train delays and traffic jams. If for any reason you do get delayed, telephone your consultant with your estimated time of arrival.
  • Creating a good rapport is important. Greet your interviewer(s) by name, with a smile and a firm handshake.
  • Throughout the interview maintain eye contact with your interviewer(s) and watch your posture.
  • Don't waffle or avoid difficult questions. When you are asked questions, remember that this is an opportunity to sell yourself. Try not to give too many 'yes' or 'no' replies.
  • If you feel the interview is not going well, do not be put off. Some companies use this technique to test your reactions.
  • Be positive and never speak negatively about your current or previous employer.
  • Remember to ask the questions you prepared before the interview. (It is acceptable to bring notes into the interview with you.)
  • Do not ask about salary, holidays or benefits at first interview stage.
  • If you are interested in the job, make sure you let the interviewer(s) know before you leave by saying why you like the role.

Thank the interviewer(s) for their time.

After the Interview 

Telephone your consultant with your interview feedback. We cannot contact the client until we know your views. Don't despair if you do not get the job. Treat every interview as experience. Practice makes perfect