suttercain Posted September 24, 2008 Share Posted September 24, 2008 Hi Everyone, I currently have data that looks like this: DE-01-001-02 DE-01-001-03 DE-01-002-01 DE-01-002-02 All I care about are the first 9 chracters, which would drop the remaining three. So basically instead of getting for results I would get the following two: DE-01-001 DE-02-002 I tried the following sequel syntax and so so far I still get the entire data string: $sql = mysql_query("SELECT *, LEFT(eo.executive_order,9) FROM device INNER JOIN device_eo ON ( device.device_id = device_eo.device_id ) INNER JOIN eo ON ( device_eo.executive_order = eo.executive_order ) WHERE eo.date_eo_rescinded IS NULL AND eo.level = '3' AND eo.url ='3' GROUP BY eo.executive_order ORDER BY device.device_mfr, eo.decs") or die(mysql_error()); Can any let me know what I am doing wrong or an alternative to this method? Thanks in advance. -SC Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/ Share on other sites More sharing options...
Barand Posted September 24, 2008 Share Posted September 24, 2008 SELECT * pulls all fields, including the unaltered fields. The LEFT bit will be in the final column of the query. Give it a column alias so you can reference it more easily. Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/#findComment-649829 Share on other sites More sharing options...
suttercain Posted September 24, 2008 Author Share Posted September 24, 2008 Awesome it worked! Thanks Barand! Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/#findComment-649845 Share on other sites More sharing options...
suttercain Posted October 14, 2008 Author Share Posted October 14, 2008 Okay, so Barand helped me big time with the previous [problem but now I am trying to take the script a step forward. I have a column which houses thee following data: DE-01-001-02 DE-01-001-03 DE-01-002-01 DE-01-002-02 I used this script: <?php $sql = mysql_query(" SELECT *, LEFT(eo.executive_order,9) AS dog, FROM device INNER JOIN device_eo ON ( device.device_id = device_eo.device_id ) INNER JOIN eo ON ( device_eo.executive_order = eo.executive_order ) GROUP BY dog ORDER BY eo.date_eo_effective DESC ") or die(mysql_error()); ?> Which gives me the following output instead of the 4 listed above. DE-01-001 DE-01-002 Now I would like to list the newest "extension" pf that number so this: DE-01-001-02 DE-01-001-03 DE-01-002-01 DE-01-002-02 Would become this DE-01-001-03 DE-01-002-02 Group by the first 9 characters and echo the hightest value (the last two characters). I tried this: <?php $sql = mysql_query(" SELECT *, LEFT(eo.executive_order,9) AS dog, MID(eo.executive_order,11,2) AS cat FROM device INNER JOIN device_eo ON ( device.device_id = device_eo.device_id ) INNER JOIN eo ON ( device_eo.executive_order = eo.executive_order ) GROUP BY dog ORDER BY eo.date_eo_effective DESC ") or die(mysql_error()); ?> But did not get the desired result. Thank in advance. Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/#findComment-665282 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 SELECT SUBSTRING_INDEX(codenum,'-',3) as partcode, MAX(codenum) FROM product GROUP BY partcode; Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/#findComment-665299 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 Are you doing this so you can generate the next unique key? Quote Link to comment https://forums.phpfreaks.com/topic/125676-useing-the-select-lefttablecolumn-syntax/#findComment-665514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.