Showing posts with label MYSQL. Show all posts
Showing posts with label MYSQL. Show all posts


In my MySQL to select between data

 Example:

SELECT id, current_role_in_khmer
FROM currentrole
WHERE id  NOT BETWEEN 11 AND 14
AND id  NOT BETWEEN 18 AND 19
AND `status`=1


in codeigniter

      $this->db->select('*');
      $this->db->from('currentrole');
      $this->db->where('status', '1');
      $this->db->where('id !=',1 );
      $this->db->where("id BETWEEN 2 and 4");
      $data['get_currentrole_leader']=$this->db->get()->result();
  • 6:14 PM
  • Unknown

SELECT * 
FROM table
WHERE CONCAT( lastName,  ' ', FristName) LIKE  '%Rachana%'
  • 8:27 PM
  • Unknown
SELECT id, 
      IF(o.office IS NULL ,'',o.office ) as office
FROM table
  • 12:48 AM
  • Unknown
To copy just structure and data use this one:
CREATE TABLE tbl_new AS SELECT * FROM tbl_old;
  • 3:07 AM
  • Unknown
Do a SELECT with a GROUP BY clause. Let's say name is the column you want to find duplicates in:

SELECT firstname, lastname , COUNT(*) c FROM civilservant GROUP BY firstname, lastname HAVING c > 1;