Jump to content

[SOLVED] Unknown column 'j_categories.category_id' in 'on clause'


jordanwb

Recommended Posts

This is the query I'm trying to run:

 

SELECT * FROM `j_categories` INNER JOIN `j_records` ON `j_categories.category_id` = `j_records.record_category_id`

 

These are the table structures:

 

CREATE TABLE `j_categories` (
  `category_id` int(10) unsigned NOT NULL auto_increment,
  `category_name` varchar(32) NOT NULL,
  PRIMARY KEY  (`category_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE `j_records` (
  `record_id` int(11) NOT NULL auto_increment,
  `record_category_id` int(10) unsigned NOT NULL,
  `record_name` varchar(64) NOT NULL,
  `record_cost` double(5,2) NOT NULL,
  `record_has_gst` tinyint(1) NOT NULL,
  `record_has_pst` tinyint(1) NOT NULL,
  `record_date` date NOT NULL,
  PRIMARY KEY  (`record_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

The error:

 

Unknown column 'j_categories.category_id' in 'on clause'

 

:-\

`j_categories.category_id`

 

 

means a table named "j_categories.category_id"

 

 

I believe you're looking for

 

`j_categories`.`category_id`

 

 

 

Or, just don't use the backticks.  They break MSSQL compatibility (and other SQL flavors too), and they're useless unless your column has a reserved name, which it shouldn't.

Or, just don't use the backticks.  They break MSSQL compatibility (and other SQL flavors too), and they're useless unless your column has a reserved name, which it shouldn't.

 

I'll keep that in mind. I removed the backticks the query works.

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.