Archive for the ‘Mysql’ Category

<?php
// output headers so that the file is downloaded rather than displayed
header(‘Content-Type: text/csv; charset=utf-8’);
header(‘Content-Disposition: attachment; filename=data.csv’);
// create a file pointer connected to the output stream
$output = fopen(‘php://output’, ‘w’);
// output the column headings
fputcsv($output, array(‘ID’,’Name’,’Email’ ));

// fetch the data
mysql_connect(‘localhost’, ‘root’, ‘password’);
mysql_select_db(‘abc’);
$sql=’SELECT name,email FROM users  ORDER BY id DESC’;
$rows = mysql_query($sql);
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row)

DISTINCT Vs GROUP BY CLOUSE

Posted: August 4, 2015 in Mysql

If we are using the GROUP BY clouse in the select statement without using any aggregate function GROUP BY behave like DISTINCT operator.

The main difference between the DISTINCT and GROUP BY clouse is that the GROUP BY clouse sort the result set while the DISTINCT operator does not..