Translate

Sunday, 6 March 2016

SQL Query to second find highest salary of Employee

n= 0 for first record salary
n = 1 second highest salary 
n= 2 third highest salary 

SELECT DISTINCT(Salary) FROM Employees ORDER BY Salary DESC LIMIT n,1


Also some other queries 

select MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) from Employee ); 


SELECT salary  FROM (SELECT DISTINCT(salary) FROM Employees ORDER BY salary DESC LIMIT 2) AS emp ORDER BY salary LIMIT 1;

Thursday, 3 March 2016

Difference between git merge and git rebase

I would suggest take an overview of this link, this would help you to understand actually how git rebase and merge works.

What is SQL Injection

-> manipulating web application parameters. 
-> bypass authorization. 
->  carry out data manipulation or reading arbitrary data

Wednesday, 2 March 2016

Difference between Include and Joins

:join :- It joins table together in sql. eg; Category.joins(:articles) SELECT categories.* FROM categories INNER JOIN articles ON articles.category_id = categories.id :includes :- Active Record ensures that all of the specified associations are loaded using the minimum possible number of queries. - It is a solution of n+1 query eg:- Article.includes(:comments).where(comments: { visible: true }) SELECT "articles"."id" AS t0_r0, ... "comments"."updated_at" AS t1_r5 FROM "articles" LEFT OUTER JOIN "comments" ON "comments"."article_id" = "articles"."id" WHERE (comments.visible = 1) I

Saturday, 27 February 2016

Difference between Ruby’s Hash and ActiveSupport’s HashWithIndifferentAccess

  • HashWithIndifferentAccess allows us to access hash key as a symbol or string
  • Ruby hash allows us to access hash key as you defined in it.

Eg:- 

Ruby hash
2.1.0 :001 > hash = {a: 1, b:2}
 => {:a=>1, :b=>2} 
2.1.0 :002 > hash = {"a"=> 1, b:2}
 => {"a"=>1, :b=>2} 
2.1.0 :003 > hash["a"]
 => 1 
2.1.0 :004 > hash[:a]
 => nil 
2.1.0 :005 > hash[:b]
 => 2 

ActiveSupport::HashWithIndifferentAccess

2.1.0 :007 > require 'active_support/core_ext/hash/indifferent_access'
 => true 
2.1.0 :008 > hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1, b:2)
 => {"a"=>1, "b"=>2} 
2.1.0 :009 > hash[:a]
 => 1 
2.1.0 :010 >  hash["a"]
 => 1 
2.1.0 :011 >