logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Left join with nulls: msg#00256

lang.perl.modules.dbix-class

Subject: Left join with nulls

Hi,

I've just started to use DBIx with Catalyst and think it's truly great
and simplifies much of what I need to do.

Alas I have a query that I can't get my head around so any advice is
appreciated. I'm trying to get a list of available categories and sub
categories for a catalogue I am looking after and have previously got
this using the following sql:-

SELECT c.id,
c.name,
sc.id,
sc.name,
CASE
WHEN cc.id IS NOT NULL THEN 1
ELSE 0
END AS cat_cat,
CASE
WHEN csc.id IS NOT NULL THEN 1
ELSE 0
END AS cat_sub_cat
FROM category c
INNER JOIN sub_category sc
ON c.id = sc.category
LEFT JOIN catalogue_cat cc
ON cc.cat = c.id
AND cc.id = 2
LEFT JOIN catalogue_subcat csc
ON csc.subcat = sc.id
AND csc.id = 2
ORDER BY c.sort_order, sc.sort_order

My tables are as follows:-

package MyApp::Model::DBSchema::Category;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('category');
__PACKAGE__->add_columns(qw/id sort_order folder name description/);

package MyApp::Model::DBSchema::CatalogueCat;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('catalogue_cat');
__PACKAGE__->add_columns(qw/id cat/);

package MyApp::Model::DBSchema::CatalogueSubCat;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('catalogue_subcat');
__PACKAGE__->add_columns(qw/id subcat/);

Thanks in advance,
Alan



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
krysalis.sandbo...    web.zope.zwiki/...    gnome.apps.gnum...    xfree86.newbie/...    editors.vim/200...    mozilla.enigmai...    boot-loaders.gr...    network.vnc.ult...    redhat.release....    java.geronimo.u...    os.netbsd.devel...    horde.wicked/20...    linux.lsb.discu...    ietf.ips/2005-0...    alsa.devel/2002...    user-groups.lin...    package-managem...    debian.devel.da...    security.cyrus....    video.gstreamer...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation