473,563 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join on multiple fields and tables

I've run into a problem I cannot solve in SQL, hope some of you can
help me. First of all, my constraints. I have to resolve all this in a
single SQL statement, as it is to be passed on to another program.
Secondly, I'm restrained to the functionality of MySQL 3.23. Upgrading
is not an option.

Ok, the problem.

I have the following tables with fields:

table0(id0,id1, id2)
table1(id1,id3)
table2(id2,id4)

table1 can contains one or more rows linked to table0 with id1, same
with table2. id3 and id4 has the same semantic meaning.

I need to list out every row in table0. I also (and this is the tricky
part) need to print out a field that indicates (Y/N) if a row in
either table1 or table2 or both exists that contain a certain value in
either id3 or id4 for that certain row in table0. NB, table1 and
table2 can contain many rows with unrealated id3/id4 values.

Listing out all that _do_ have this value is dead easy, the problem
arises when I also need to list out the rest that do not have this
value.

Here is code that lists out all that do have the row, what I need help
with is to also list out the rest and indicate this with a Y/N field.
(Beware of simple mistakes in this code, its just an example)

SELECT table0.id1,tabl e0.id2 FROM table0
LEFT JOIN table1 ON table0.id1 = table1.id1
LEFT JOIN table2 ON table0.id2 = table2.id2
WHERE table1.id3 = '147' OR table2.id4 = '147;

Can somebody please help with this?

--
regards
Stein
Jul 20 '05 #1
0 1978

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

Similar topics

0
12997
by: Petre Agenbag | last post by:
Hi List Me again. I'm trying to return from multiple tables, the records that have field "information_sent" between two dates. The tables are all related by means of the id of the entry in the main table, ie.. main id entity_name ...
1
422
by: Mike | last post by:
I am not a sql person and could use some help with a delete...here is what I want: I have the following tables/fields (only including necessary fields) answers result_id results result_id
1
16641
by: TeleTech1212 | last post by:
I am trying to select specific columns from multiple tables based on a common identifier found in each table. For example, the three tables: PUBACC_AC PUBACC_AM PUBACC_AN each have a common column:
6
2634
by: Christopher Harrison | last post by:
Is there a way to store an indefinite number of keys in one field and self join them? Imagine, for example, you have a table of users with a "friends" column. Say user 1 is friends with users 9, 7, 24 and 6; then would it be possible to store this array/list/whatever-you-want-to-call-it into user 1's friends cell and extract the join in a...
7
5827
by: Pino | last post by:
Hi, to everybody, let's consider this scenario: you have 1 data-table and 10 dictionary-tables; the data-table has 5 million records and 30 columns, 10 of these columns have a foreign-key to the dictionary-tables: the dictionary-tables have (almsot all) only two columns (code and description) and a low number of records (less than 100 in...
1
1439
by: Justin | last post by:
Hello, I have a scenario where I have unique identifiers in about 25 tables, each table has varying fields - eg. Table #1 Table #2 Table #3 Table #4 --------- -------- -------- -------- sample_no sample_no sample_no sample_no coords test1 test2 test3
2
4665
by: dskillingstad | last post by:
I would really appreciate someone's help on this, or at least point me in the right direction.... I'm working on a permit database that contains 12 tables, and rather than list all of the tables, I'll just list a few, as the links are the same for all tables. These tables are: tblPermitMain tblApplicant tblContractor tblEngineer
52
6276
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the...
5
4131
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I delete a row, only the child record is deleted from the source tables; the parent record is still there...which is what I wanted. Now display fields...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.