![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Firstly, here's the example structure and data: +---------------+ | log | +---------------+ | id | | approval_date | | approved_by | | page_title | +---------------+ Data: 4, '2006-01-01 08:32:17', 'admin3', 'index' .... +---------------+ | content | +---------------+ | page_title | | page_uri | +---------------+ Data: 'PREFIX_index', 'index.html' 'index', 'index.html' 'ARCH_index', 'index.html' What I want to do is select log.approval_date, log.approved_by and content.page_uri for the records... The twist is that I want to join the tables based on the page_title where they will be *different* values in each table. For instance, I want to get the following: '2006-01-01 08:32:17', 'admin3', 'index.html' This would require that the following would be the constraint for the JOIN: CONCAT('PREFIX_', log.page_title) = content.page_title This is the first thing I tried: SELECT content.page_uri , log.approval_date , log.approved_by , REPLACE(content.page_title,'PREFIX_','') as xx FROM content INNER JOIN log ON log.page_title = xx WHERE content.page_title LIKE 'PREFIX_%' *** MySQL said: #1054 - Unknown column 'xx' in 'on clause' Then I tried this: SELECT content.page_uri , log.approval_date , log.approved_by FROM content INNER JOIN log ON CONCAT('PREFIX_', log.page_title ) = content.page_title WHERE content.page_title LIKE 'PREFIX_%' .... this returned data, but looks like it's pretty much everything in the log table coupled with the matching entries from the content table (from the WHERE clause). Can anyone get me in the right direction for this? -- Justin Koivisto, ZCE - justin@koivi.com http://koivi.com | |||
| | #2 | ||
| Justin Koivisto wrote: > Firstly, here's the example structure and data: > > +---------------+ > | log | > +---------------+ > | id | > | approval_date | > | approved_by | > | page_title | > +---------------+ > > Data: > 4, '2006-01-01 08:32:17', 'admin3', 'index' > ... > > +---------------+ > | content | > +---------------+ > | page_title | > | page_uri | > +---------------+ > > Data: > 'PREFIX_index', 'index.html' > 'index', 'index.html' > 'ARCH_index', 'index.html' > > > What I want to do is select log.approval_date, log.approved_by and > content.page_uri for the records... The twist is that I want to join the > tables based on the page_title where they will be *different* values in > each table. > > For instance, I want to get the following: > > '2006-01-01 08:32:17', 'admin3', 'index.html' > > This would require that the following would be the constraint for the JOIN: > CONCAT('PREFIX_', log.page_title) = content.page_title > > This is the first thing I tried: > SELECT > content.page_uri > , log.approval_date > , log.approved_by > , REPLACE(content.page_title,'PREFIX_','') as xx > FROM content > INNER JOIN log > ON log.page_title = xx > WHERE > content.page_title LIKE 'PREFIX_%' > > *** MySQL said: #1054 - Unknown column 'xx' in 'on clause' > > Then I tried this: > SELECT > content.page_uri > , log.approval_date > , log.approved_by > FROM content > INNER JOIN log > ON CONCAT('PREFIX_', log.page_title ) = content.page_title > WHERE > content.page_title LIKE 'PREFIX_%' > > ... this returned data, but looks like it's pretty much everything in > the log table coupled with the matching entries from the content table > (from the WHERE clause). > > Can anyone get me in the right direction for this? > By the lack of replies, I will just assume that this is not possible and abandon the thought. -- Justin Koivisto, ZCE - justin@koivi.com http://koivi.com | |||
| Featured Websites | ||||
|
![]() |
| Tags: field, joins, select, tables, values |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why does 'SELECT * FROM countries' truncate characters and SELECT country FROM countries does not ? | PRS | Database | 0 | 05-31-2007 8:48 PM |
| Only output values from a table that are NOT NULL? | Bill Y. Barool | Database | 1 | 05-31-2007 8:43 PM |
| docs about access tables, operation tables, volume tables | BradPitt | Database | 0 | 05-31-2007 8:42 PM |
| SELECT DISTINCT with Joins? | Aapo V | Database | 1 | 05-31-2007 8:39 PM |
| cmyk values in a bitmap | QuickDraw Steve | Graphics in general | 3 | 05-28-2007 7:55 PM |
| Featured Websites | ||||
|