Reputation: 1330
I'm in the process of creating a table then display records. i want to display users height in 'inch' format but it will store it in 'cm' forma in users table. Now I want to know which way will give me faster result ?
Using JOIN
// to select records
SELECT *.u FROM, h.height_inch user as u join height as h on u.height_cm =h.height_cm
WHERE u.user_id = 2 AND ...;
//for display in php
foreach($all_records AS $key => $val) {
echo $val['height_inch'];
}
OR Single User table (Faster/slower than) :
// to select records
SELECT * user WHERE u.user_id = 2 AND ...;
//for display in php
foreach($all_records AS $key => $val) {
$height_in_cm = $val['height_inch']
$height_in_inch= convert_to_inch($height_in_cm); //function for convert height cm to inch..
echo $height_in_inch;
}
Upvotes: 0
Views: 52
Reputation: 7715
An even faster alternative would be to simply perform the arithmetic in SQL so you don't have to store fixed conversion data or iterate over the results.
SELECT height_cm, height_inches as (height_cm / 2.54) FROM table;
Upvotes: 3