Doing INTERSECT and MINUS in MySQL
By Carsten | October 3, 2005
Doing an INTERSECT
An INTERSECT is simply an inner join where we compare the tuples of one table with those of the other, and select those that appear in both while weeding out duplicates. So
SELECT member_id, name FROM a
INTERSECT
SELECT member_id, name FROM b
can simply be rewritten to
SELECT a.member_id, a.name
FROM a INNER JOIN b
USING (member_id, name)
Performing a MINUS
To transform the statement
SELECT member_id, name FROM a
MINUS
SELECT member_id, name FROM b
into something that MySQL can process, we can utilize subqueries (available from MySQL 4.1 onward). The easy-to-understand transformation is:
SELECT DISTINCT member_id, name
FROM a
WHERE (member_id, name) NOT IN
(SELECT member_id, name FROM table2);
Of course, to any long-time MySQL user, this is immediately obvious as the classical use-left-join-to-find-what-isn’t-in-the-other-table:
SELECT DISTINCT a.member_id, a.name
FROM a LEFT JOIN b USING (member_id, name)
WHERE b.member_id IS NULL
Reference:
Wednesday, April 27, 2011
Kill a Process by Process Name from Ubuntu Command Line
There are a number of ways to kill a process if you know the name of the process. Here’s a couple different ways you can accomplish this. We are going to assume that the process we are trying to kill is named irssi
These techniques can be useful in shell scripts, where you wouldn’t know the process ID and would need to restart or kill a process.
Reference:
kill $(pgrep irssi) killall -v irssi pkill irssi kill `ps -ef | grep irssi | grep -v grep | awk ‘{print $2}’`
These techniques can be useful in shell scripts, where you wouldn’t know the process ID and would need to restart or kill a process.
Reference:
Tuesday, April 26, 2011
Simple php multiple processes
function fork() { $pid = pcntl_fork(); if ($pid === -1) { // Error echo 'Process could not be forked'; } else if ($pid) { // Parent echo 'pid of the child process:'.$pid."\n"; } else { // Child sleep(30); } } fork();
How to run a php file in terminal
You can also create php scripts designed to run in the terminal like so:
1) Fire up a text editor and create your file, eg:
2) Give the script execute permissions:
3) Execute your script:
This is all assuming you have the CLI version of PHP. FC installs this by default.
Reference:
# php -f php-file.php
1) Fire up a text editor and create your file, eg:
#!/usr/bin/php // ^^ that line tells the command line that the file should be parsed by the php CLI interpreter echo "Hello terminal\n";
2) Give the script execute permissions:
# chmod +x script.php
3) Execute your script:
# ./script.php Hello terminal
This is all assuming you have the CLI version of PHP. FC installs this by default.
Reference:
Test code listing
// Comment public class Testing { public Testing() { } public void Method() { /* Another Comment on multiple lines */ int x = 9; } }
/** * SyntaxHighlighter */ public class HelloWorld extends ActionSupport { private String name; private String message; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String execute() { setMessage("Hello, " + getName()); return "SUCCESS"; } }
Friday, April 22, 2011
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Problem:
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Reason:
The restrictions of PDO to the parameters bound are very strict, so you bind must exactly the same as that present in the query statement. No more parameter can be bound.
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Reason:
The restrictions of PDO to the parameters bound are very strict, so you bind must exactly the same as that present in the query statement. No more parameter can be bound.
Thursday, April 21, 2011
Subscribe to:
Posts (Atom)