Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Thursday, 26 May 2016

What's the difference between MyISAM and InnoDB in Mysql db

MYISAM:
  1. MYISAM supports Table-level Locking
  2. MyISAM designed for need of speed
  3. MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
  4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
  5. MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.
  6. MYISAM supports fulltext search
  7. You can use MyISAM, if the table is more static with lots of select and less update and delete.
INNODB:
  1. InnoDB supports Row-level Locking
  2. InnoDB designed for maximum performance when processing high volume of data
  3. InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
  4. InnoDB stores its tables and indexes in a tablespace
  5. InnoDB supports transaction. You can commit and rollback with InnoDB

Friday, 29 January 2016

How to find count of multiple fields in MongoDb

Problem Statement:
I have a use case where i need to find the count of activity done on JobId.
I have a mongodb collection jobslog which has following data

jobId,action
1 a (apply)
2       v (view)
3      a (apply)
1 v (view)

I knew the query in mysql
select count(a),count(v) from jobslog group by jobId

But I do not know how to do it in Mongo.So i did lots of search on google for that.

Solution:
Query In MongoDB
db.jobslog.aggregate([
                    { $group: {
                        _id: "$jobId",
                         view_count: { $sum: {
                                        $cond: [ { $eq: [ '$a', 'v' ] }, 1, 0 ]
                                     } },
                         apply_count: { $sum: {
                                        $cond: [ { $eq: [ '$a', 'a' ] }, 1, 0 ]
                                     } },
                     }},
                     { $out : output_collection_name }

])

Thursday, 28 January 2016

uppercase to lower case mysql query

uppercase to lower case query

To select all the data from the above table and convert it to lower case you would do this:
SELECT LOWER(name) FROM mytable
This would return this:
+----------------------------+
| LOWER(name)                |
+----------------------------+
| lorem ipsum dolor sit amet |
| ut purus est               |
| leo sed condimentum semper |
| donec velit neque          |
| maecenas ullamcorper       |
+----------------------------+