Thursday, August 19, 2010

MySQL - Views

MySQL View is very useful to see data in one view place. IF we have multiple tables and data's and if you specifically interested to view specific data you can create view below is example.

CREATE VIEW test.v AS SELECT * FROM t;

DROP VIEW IF EXISTS im_job_info;
CREATE VIEW im_job_info AS
SELECT DISTINCT a.req_id , a.source_req_id , a.source, a.sub_source,
b.job_id, b.external_target_id, e.operation_type, b.status AS 'jobstatus', a.status AS 'requeststatus',
c.send_status, b.last_status, b.priority, b.production_system_id,
a.received_at,b.queued_at, c.sent_at

FROM
request_message a, job b, response_message c, external_target d,
operation_type e

WHERE
a.req_id = b.req_id AND c.im_req_id = b.req_id AND
d.external_target_id = b.external_target_id AND
d.operation_type_id = e.operation_type_id;

Query to List all the views from the db
Syntax : 
     SHOW FULL TABLES IN `db_name` WHERE TABLE_TYPE LIKE 'VIEW';

No comments :

// Below script tag for SyntaxHighLighter