Friday 31 August 2012

mysql joins

a mysql join

ties 2 tables.

shows all of stockbook, and using a non-descriptive index within stockbook table i.e a number, it displays the more descriptive column from the other table

This works even if the relationship is not enabled, but enabling the relationship prevents incorrect entries by forcing integrity with the drop down list

SELECT `stockbook`.*, `categories`.`type`
FROM stockbook, categories WHERE `stockbook`.`categories` = `categories`.`category_id`

example from

http://www.tizag.com/mysqlTutorial/mysqljoins.php

and statement and ordering with AS command for column ambiguity resolution

SELECT `stockbook`.*, `categories`.`type`,`locations`.`notes` AS 'Location Notes'
FROM stockbook, categories,locations WHERE `stockbook`.`categories` =  `categories`.`category_id` && `stockbook`.`location` = `locations`.`location_id` ORDER BY `stockbook`.`product_id`

Mysql phpmyadmin search replace

phpmyadmin syntax, note no speech marks on tablename or field name

UPDATE tablename SET field = REPLACE ( 
field, 
'HLLOWRDCHG', 
'HELLOWORLDCHANGE');

Tuesday 28 August 2012

VI editor tricks

Word count


http://vim.wikia.com/wiki/Word_count

find text, then replace part of text

There is another form of line addressing called global addressing. It is similar to the % (all lines) address, but allows you to limit the search and replace action by specifying certain text that must appear in a line before the search and replace action is applied to it. An example is show below. The syntax shown below would read "for all lines containing `some text', search for `search text' and replace any instances with `replacement text.'"

:g/some text/s/search text/replacement text/

other stuff


:%s/test/mytest/gIc

arguments g=global, I=dont ignore case, c=confirmation required

regex

:%s/[A-Z]', '2'//gn

count occurences of: letter then comma then space then apostrophe then 2 apostrophe