<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Design Talk &#187; mysql query</title>
	<atom:link href="http://www.web-design-talk.co.uk/tag/mysql-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-design-talk.co.uk</link>
	<description>Web Design &#38; Development Blog</description>
	<lastBuildDate>Wed, 28 Jul 2010 21:50:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL Cheatsheet &#8211; Useful MySQL Queries</title>
		<link>http://www.web-design-talk.co.uk/128/mysql-cheatsheet-useful-mysql-queries/</link>
		<comments>http://www.web-design-talk.co.uk/128/mysql-cheatsheet-useful-mysql-queries/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 19:06:50 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql query]]></category>
		<category><![CDATA[sample mysql queries]]></category>

		<guid isPermaLink="false">http://www.web-design-talk.co.uk/?p=128</guid>
		<description><![CDATA[Page rank 5 Page rank 5 Page rank 5 Page rank 5 What follows is a list of some very useful MySQL queries for use in projects, enjoy. I won&#8217;t go into detail how and why they work, I&#8217;ll leave that up to you /*** select records from the previous day ***/ SELECT * FROM [...]]]></description>
			<content:encoded><![CDATA[<div id="rank_jit_com_main" style="border: 0px none; margin: 0px; padding: 0px; position: absolute; top: 126px; left: 519px; line-height: normal; background-color: transparent; z-index: 99999; width: 70px; height: 46px; visibility: hidden;">
<div style="visibility: inherit;">
<table style="margin: 0pt; padding: 0px; width: 70px; height: 36px; background-color: transparent; font-family: Lucida Grande,sans-serif; font-size: 9px; z-index: 200000; border-collapse: separate; visibility: inherit; border: 0px 1px 1px 0px none solid solid none -moz-use-text-color #e0e0e0 #e0e0e0 -moz-use-text-color;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="background-color: transparent;">
<td style="margin: 0px; padding: 0px; height: 16px; background-color: transparent; text-align: center; vertical-align: middle; visibility: inherit; border: 0px 0px 1px none none solid -moz-use-text-color -moz-use-text-color #e0e0e0;">
<div style="border: 0pt none; margin: 0pt; padding: 0pt; background-color: transparent;"></div>
</td>
<td style="margin: 0px; padding: 0px; width: 20px; height: 16px; text-align: center; vertical-align: middle; background-color: white; visibility: inherit; border: 1px 0px 1px 1px solid none solid solid #e0e0e0 -moz-use-text-color #e0e0e0 #e0e0e0;" colspan="2" align="center"><img id="rank_jit_pin" style="border: 0px none; margin: 0px; padding: 0px; display: inline; cursor: pointer; width: 16px; height: 16px; vertical-align: bottom; visibility: inherit; background-color: transparent;" src="http://www.rankjit.com/extension/img/pin.gif" alt="" /></td>
</tr>
<tr style="margin: 0px; padding: 0px; background-color: white; visibility: inherit; border: 1px 0px 0px solid none none #e0e0e0 -moz-use-text-color -moz-use-text-color;">
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; color: #000000; font-size: 9px; font-weight: normal; text-align: center; vertical-align: middle; height: 10px; background-color: white; visibility: inherit; border: 0px 0px 0px 1px none none none solid -moz-use-text-color -moz-use-text-color -moz-use-text-color #e0e0e0;" align="center">Page rank</td>
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; text-align: center; vertical-align: middle; background-color: white; border-spacing: 1px; font-size: 14px; width: 20px; height: 20px; color: white; visibility: inherit; border: 0px 0px 0px 1px none none none solid -moz-use-text-color -moz-use-text-color -moz-use-text-color #e0e0e0;" rowspan="2" align="center" valign="middle">
<div style="border: 0px none; margin: 1px; padding: 0px; width: 20px; height: 20px; background-color: #848484; visibility: inherit;">
<div id="rank_jit_resultContainer" style="border: 0px none; margin: 0px; padding: 0px; background-color: transparent; width: 20px; height: 20px; line-height: 20px; vertical-align: middle; color: white; visibility: inherit; text-align: center;">5</div>
</div>
</td>
</tr>
<tr>
<td style="margin: 0px; padding: 0px; height: 10px; vertical-align: middle; background-color: white; visibility: inherit; border: 0px 0px 0px 1px none none none solid -moz-use-text-color -moz-use-text-color -moz-use-text-color #e0e0e0;" align="center">
<div style="border: 1px solid #e0e0e0; margin: 0px 0px 1px 1px; padding: 0px; width: 38px; height: 4px; visibility: inherit;"></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="border: 0pt none; margin: 0pt; padding: 0pt; overflow: hidden; z-index: 9999; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: auto; top: 39.5px; line-height: normal; background-color: transparent; visibility: inherit; width: 10px; height: 10px; right: 50px;"><img style="border: 0pt none; margin: 0pt; padding: 0pt; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: 0px; top: 0px; line-height: normal; background-color: transparent; visibility: inherit; z-index: 99999;" src="http://www.rankjit.com/extension/img/pointer.gif" alt="" /></div>
</div>
<div id="rank_jit_com_main" style="border: 0px none; margin: 0px; padding: 0px; position: absolute; top: 126px; left: 519px; line-height: normal; background-color: transparent; z-index: 99999; width: 70px; height: 46px; visibility: hidden;">
<div style="visibility: inherit;">
<table style="margin: 0pt; padding: 0px; width: 70px; height: 36px; background-color: transparent; font-family: Lucida Grande,sans-serif; font-size: 9px; z-index: 200000; border-collapse: separate; visibility: inherit;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="background-color: transparent;">
<td style="margin: 0px; padding: 0px; height: 16px; background-color: transparent; text-align: center; vertical-align: middle; visibility: inherit;"></td>
<td style="margin: 0px; padding: 0px; width: 20px; height: 16px; text-align: center; vertical-align: middle; background-color: white; visibility: inherit;" colspan="2" align="center"><img id="rank_jit_pin" style="border: 0px none; margin: 0px; padding: 0px; display: inline; cursor: pointer; width: 16px; height: 16px; vertical-align: bottom; visibility: inherit; background-color: transparent;" src="http://www.rankjit.com/extension/img/pin.gif" alt="" /></td>
</tr>
<tr style="margin: 0px; padding: 0px; background-color: white; visibility: inherit; border: 1px 0px 0px solid none none #e0e0e0 -moz-use-text-color -moz-use-text-color;">
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; color: #000000; font-size: 9px; font-weight: normal; text-align: center; vertical-align: middle; height: 10px; background-color: white; visibility: inherit;" align="center">Page rank</td>
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; text-align: center; vertical-align: middle; background-color: white; border-spacing: 1px; font-size: 14px; width: 20px; height: 20px; color: white; visibility: inherit;" rowspan="2" align="center" valign="middle">
<div style="border: 0px none; margin: 1px; padding: 0px; width: 20px; height: 20px; background-color: #848484; visibility: inherit;">
<div id="rank_jit_resultContainer" style="border: 0px none; margin: 0px; padding: 0px; background-color: transparent; width: 20px; height: 20px; line-height: 20px; vertical-align: middle; color: white; visibility: inherit; text-align: center;">5</div>
</div>
</td>
</tr>
<tr>
<td style="margin: 0px; padding: 0px; height: 10px; vertical-align: middle; background-color: white; visibility: inherit;" align="center"></td>
</tr>
</tbody>
</table>
</div>
<div style="border: 0pt none; margin: 0pt; padding: 0pt; overflow: hidden; z-index: 9999; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: auto; top: 39.5px; line-height: normal; background-color: transparent; visibility: inherit; width: 10px; height: 10px; right: 50px;"><img style="border: 0pt none; margin: 0pt; padding: 0pt; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: 0px; top: 0px; line-height: normal; background-color: transparent; visibility: inherit; z-index: 99999;" src="http://www.rankjit.com/extension/img/pointer.gif" alt="" /></div>
</div>
<div id="rank_jit_com_main" style="border: 0px none; margin: 0px; padding: 0px; position: absolute; top: 126px; left: 519px; line-height: normal; background-color: transparent; z-index: 99999; width: 70px; height: 46px; visibility: hidden;">
<div style="visibility: inherit;">
<table style="margin: 0pt; padding: 0px; width: 70px; height: 36px; background-color: transparent; font-family: Lucida Grande,sans-serif; font-size: 9px; z-index: 200000; border-collapse: separate; visibility: inherit;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="background-color: transparent;">
<td style="margin: 0px; padding: 0px; height: 16px; background-color: transparent; text-align: center; vertical-align: middle; visibility: inherit;"></td>
<td style="margin: 0px; padding: 0px; width: 20px; height: 16px; text-align: center; vertical-align: middle; background-color: white; visibility: inherit;" colspan="2" align="center"><img id="rank_jit_pin" style="border: 0px none; margin: 0px; padding: 0px; display: inline; cursor: pointer; width: 16px; height: 16px; vertical-align: bottom; visibility: inherit; background-color: transparent;" src="http://www.rankjit.com/extension/img/pin.gif" alt="" /></td>
</tr>
<tr style="margin: 0px; padding: 0px; background-color: white; visibility: inherit; border: 1px 0px 0px solid none none #e0e0e0 -moz-use-text-color -moz-use-text-color;">
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; color: #000000; font-size: 9px; font-weight: normal; text-align: center; vertical-align: middle; height: 10px; background-color: white; visibility: inherit;" align="center">Page rank</td>
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; text-align: center; vertical-align: middle; background-color: white; border-spacing: 1px; font-size: 14px; width: 20px; height: 20px; color: white; visibility: inherit;" rowspan="2" align="center" valign="middle">
<div style="border: 0px none; margin: 1px; padding: 0px; width: 20px; height: 20px; background-color: #848484; visibility: inherit;">
<div id="rank_jit_resultContainer" style="border: 0px none; margin: 0px; padding: 0px; background-color: transparent; width: 20px; height: 20px; line-height: 20px; vertical-align: middle; color: white; visibility: inherit; text-align: center;">5</div>
</div>
</td>
</tr>
<tr>
<td style="margin: 0px; padding: 0px; height: 10px; vertical-align: middle; background-color: white; visibility: inherit;" align="center"></td>
</tr>
</tbody>
</table>
</div>
<div style="border: 0pt none; margin: 0pt; padding: 0pt; overflow: hidden; z-index: 9999; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: auto; top: 39.5px; line-height: normal; background-color: transparent; visibility: inherit; width: 10px; height: 10px; right: 50px;"><img style="border: 0pt none; margin: 0pt; padding: 0pt; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: 0px; top: 0px; line-height: normal; background-color: transparent; visibility: inherit; z-index: 99999;" src="http://www.rankjit.com/extension/img/pointer.gif" alt="" /></div>
</div>
<div id="rank_jit_com_main" style="border: 0px none; margin: 0px; padding: 0px; position: absolute; top: 126px; left: 519px; line-height: normal; background-color: transparent; z-index: 99999; width: 70px; height: 46px; visibility: hidden;">
<div style="visibility: inherit;">
<table style="margin: 0pt; padding: 0px; width: 70px; height: 36px; background-color: transparent; font-family: Lucida Grande,sans-serif; font-size: 9px; z-index: 200000; border-collapse: separate; visibility: inherit;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="background-color: transparent;">
<td style="margin: 0px; padding: 0px; height: 16px; background-color: transparent; text-align: center; vertical-align: middle; visibility: inherit;"></td>
<td style="margin: 0px; padding: 0px; width: 20px; height: 16px; text-align: center; vertical-align: middle; background-color: white; visibility: inherit;" colspan="2" align="center"><img id="rank_jit_pin" style="border: 0px none; margin: 0px; padding: 0px; display: inline; cursor: pointer; width: 16px; height: 16px; vertical-align: bottom; visibility: inherit; background-color: transparent;" src="http://www.rankjit.com/extension/img/pin.gif" alt="" /></td>
</tr>
<tr style="margin: 0px; padding: 0px; background-color: white; visibility: inherit; border: 1px 0px 0px solid none none #e0e0e0 -moz-use-text-color -moz-use-text-color;">
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; color: #000000; font-size: 9px; font-weight: normal; text-align: center; vertical-align: middle; height: 10px; background-color: white; visibility: inherit;" align="center">Page rank</td>
<td style="margin: 0px; padding: 0px; font-family: Lucida Grande,sans-serif; text-align: center; vertical-align: middle; background-color: white; border-spacing: 1px; font-size: 14px; width: 20px; height: 20px; color: white; visibility: inherit;" rowspan="2" align="center" valign="middle">
<div style="border: 0px none; margin: 1px; padding: 0px; width: 20px; height: 20px; background-color: #848484; visibility: inherit;">
<div id="rank_jit_resultContainer" style="border: 0px none; margin: 0px; padding: 0px; background-color: transparent; width: 20px; height: 20px; line-height: 20px; vertical-align: middle; color: white; visibility: inherit; text-align: center;">5</div>
</div>
</td>
</tr>
<tr>
<td style="margin: 0px; padding: 0px; height: 10px; vertical-align: middle; background-color: white; visibility: inherit;" align="center"></td>
</tr>
</tbody>
</table>
</div>
<div style="border: 0pt none; margin: 0pt; padding: 0pt; overflow: hidden; z-index: 9999; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: auto; top: 39.5px; line-height: normal; background-color: transparent; visibility: inherit; width: 10px; height: 10px; right: 50px;"><img style="border: 0pt none; margin: 0pt; padding: 0pt; font-style: normal; font-weight: normal; font-family: trebuchet ms,arial,helvetica,sans-serif; float: none; position: absolute; left: 0px; top: 0px; line-height: normal; background-color: transparent; visibility: inherit; z-index: 99999;" src="http://www.rankjit.com/extension/img/pointer.gif" alt="" /></div>
</div>
<p>What follows is a list of some very useful MySQL queries for use in projects, enjoy. I won&#8217;t go into detail how and why they work, I&#8217;ll leave that up to you <img src='http://www.web-design-talk.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: sql;">
/*** select records from the previous day ***/
SELECT * FROM users WHERE TO_DAYS(last_login) = ( TO_DAYS(NOW()) - 1 )

/*** select records from last 90 minutes ***/
SELECT* FROM users DATE_SUB(NOW(),INTERVAL 90 MINUTE);

/*** select records from last 1hr 5 mins ***/
SELECT DATE_ADD('1970-01-01 12:00:00', INTERVAL CAST(6/4 AS DECIMAL(3,1)) HOUR_MINUTE);

/*** select records from last hour ***/
select DATE_SUB(NOW(), INTERVAL 1 HOUR);

/*** using the SIGN function to mark a number as positive, negative or null ***/
SELECT backlist, SIGN(backlist) AS user_to_backlist
FROM users
WHERE user_banned IS NOT NULL;

/*** select records from last week ***/
select DATE_SUB(NOW(), INTERVAL 1 WEEK);

/*** get the last day of next month ***/
SELECT LAST_DAY('2006-03-06' + INTERVAL 1 MONTH) AS last_day;

/*** select unique records only ***/
SELECT user_name FROM users GROUP BY users HAVING ( COUNT(user_name) = 1 );

/*** select records from one table that are in another table i.e. all the customers that have placed an order ***/
SELECT DISTINCT cust.customer_id, cust.customer_name
FROM cust INNER JOIN orders ON cust.customer_id = orders.customer_id;

/*** insert data from one table into another ***/
INSERT INTO customers(customer_id, customer_name)
SELECT cus_key, cus_name
FROM customers_2 WHERE customer_name LIKE 'W%';

/*** update information based upon a seperate table ***/
UPDATE cust SET status = '1'
FROM orders WHERE orderdate &gt; '2009-01-01' and orders.customer_id = cus.customer_id;

/*** classic self join example - who is an emoployees manager ***/
SELECT emp.empID, emp.Name, emp.Salary, managers.Name AS manager_name
FROM emp
LEFT JOIN emp AS manager_name
ON emp.ManagerID = Manager.EmployeeID
WHERE (emp.empID= '123456');

/*** using UNION to combine results from multiple queries into a single table ***/
SELECT users.name
FROM users WHERE (users.name BETWEEN 'A%' AND 'M%')
UNION
SELECT banned_users.name FROM banned_users
WHERE (banned_users.name BETWEEN 'A%' AND 'M%');

/*** concatenate column data into a single column ***/
SELECT CONCAT(emp.firstname, '-', emp.lastname) AS emp_full_name FROM emp;

/*** select count of records for each hour ***/
SELECT HOUR(last_login) AS last_login_hour, COUNT(*) AS the_count FROM users GROUP BY HOUR(last_login);

/*** import a csv file ***/
LOAD DATA INFILE '/path/xxx.csv' INTO users_table csv_test_table FIELDS TERMINATED BY ',' LINES TERMINATED BY &quot;\n&quot; (user_name, access_level , user_email);

/*** display current mysql user ***/
SELECT USER();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.web-design-talk.co.uk/128/mysql-cheatsheet-useful-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
