{"id":64,"date":"2008-02-23T21:49:24","date_gmt":"2008-02-23T13:49:24","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/mysql-multiple-table-query-output-into-file\/"},"modified":"2008-02-23T21:49:24","modified_gmt":"2008-02-23T13:49:24","slug":"mysql-multiple-table-query-output-into-file","status":"publish","type":"post","link":"http:\/\/www.sysadmindayph.com\/blog\/mysql-multiple-table-query-output-into-file\/","title":{"rendered":"mysql: Multiple Table Query, Output into File"},"content":{"rendered":"<p>Got a request from the boss today to extract all users plus their contact numbers from the Paging server<\/p>\n<p>Server is a Red Hat Enterprise Linux AS release 4, running LAMP.<\/p>\n<p>The data needed are located in several tables, so we need to query all relevant tables in the databse:<\/p>\n<blockquote><p> mysql&gt; SELECT users.username, users.emailaddress, user_services.current_service FROM users, user_services WHERE users.username=user_services.username<\/p><\/blockquote>\n<p>The statement above queries two tables &#8211; <em>users<\/em> and <em>user_services<\/em>, as show from the expressin &#8216;FROM users, user_services&#8217;. The record in users table that information is required are in the username and emailaddress record. On user_services, it&#8217;s current_services. The WHERE sets the limit condition.<\/p>\n<p>To send that output to a file, we use the INTO OUTFILE &#8216;&lt;\/path\/to\/file&gt;&#8217;.<\/p>\n<p>So, that&#8217;s<\/p>\n<blockquote><p>mysql&gt; SELECT users.username, users.emailaddress, user_services.current_service FROM users, user_services WHERE users.username=user_services.username INTO OUTFILE &#8216;\/tmp\/tempfile.txt&#8217;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Got a request from the boss today to extract all users plus their contact numbers from the Paging server Server is a Red Hat Enterprise Linux AS release 4, running LAMP. The data needed are &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,22,8],"tags":[],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-linux","category-mysql","category-tips"],"_links":{"self":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":0,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}