473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Very strange table JOIN

Hello

I'v got the following tables

CREATE TABLE `aa` (
`aaid` tinyint(4) NOT NULL auto_increment,
`test` varchar(255) NOT NULL default '',
PRIMARY KEY (`aaid`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;

INSERT INTO `aa` (`aaid`, `test`) VALUES (1, 'row1');
INSERT INTO `aa` (`aaid`, `test`) VALUES (2, 'row2');
INSERT INTO `aa` (`aaid`, `test`) VALUES (3, 'row3');

CREATE TABLE `bb` (
`bbid` tinyint(3) unsigned NOT NULL auto_increment,
`prop` varchar(255) NOT NULL default '',
`value` enum('Y','N') NOT NULL default 'Y',
`linkto` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`bbid`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;

INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (1,
'prop1','Y', 1);
INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (2,
'prop_cool','N', 2);
INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (3,
'lalala','Y',1);
INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (4,
'wolle','Y', 3);
INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (5,
'rose', 'N',3);
INSERT INTO `bb` (`bbid`, `prop`, `value`, `linkto`) VALUES (6,
'kaufe','N', 3);

I want to do the following
SELECT * FROM aa
LEFT JOIN bb on (aa.aaid = bb.linkto)...

this works fine, but i want to use the values of bb.prop as new
fields!

--------------------------------------------------------------
||aaid | test | prop1 | lalala || ... wolle | rose | kaufe |
---------------------------------
|| 1 | row1 | Y | Y ||
----------------------------------
.......
---------------------------------

as example aa.lalala shall become a new field of the resultset
(lala is the value of a row from the bb table (field prop)
How could I realise this?

I hope you could understand what I mean... ;)

The point is to use a "value of a field" of one table, as a field of
the resultset, having the name of the value of the first table, and
having as value the value of another field in the first table (uff...)

Thanks in advance

Marc
Jul 20 '05 #1
0 1324

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: StealthBananaT | last post by:
My database has two tables - films has 10,000 records and reviews has 20,000 records. Whenever I try to list all the films and the count of its reviews, MySQL locks and I have to restart the...
0
by: Marc Giombetti | last post by:
Hello I'v got the following tables CREATE TABLE `aa` ( `aaid` tinyint(4) NOT NULL auto_increment, `test` varchar(255) NOT NULL default '', PRIMARY KEY (`aaid`) ) TYPE=MyISAM...
2
by: Neil | last post by:
I have a strange situation. I have a stored procedure that is hanging upon execution, but only some machines and not others. The db is an Access 2000 MDB using ODBC linked tables and a SQL 7 back...
5
by: krystoffff | last post by:
I currently have PostgreSQL 7.1 installed on a server with about 700 Mb of RAM. I have many problems of speed with a database I created. For example, it took almost 12 sec to run the query...
4
by: Andrei Ivanov | last post by:
Hello, I have 2 tables: CREATE TABLE products ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL ); CREATE TABLE products_daily_compacted_views ( product ...
16
by: Justin Koivisto | last post by:
I am trying to create a query to use as a report record source. Below is what I want to do (this was tested and works with a MySQL web script): SELECT contacts.id, contacts.email,...
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
8
by: Richard | last post by:
Hello! I have this piece of SQL code: UPDATE a SET Field1 = c.Field1 FROM a INNER JOIN b ON a.GUID1 = b.GUID1 INNER JOIN c ON b.GUID2 = c.GUID2 WHERE c.Type = 1
4
prn
by: prn | last post by:
Hi Folks, Sorry if I have the forum wrong, It's more a SQL question than a SQL Server question, but it is intended to run on MS SQL Server at least. :) I'm trying to construct a query and am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.