473,385 Members | 1,343 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,385 software developers and data experts.

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,table0.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 1969

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

Similar topics

0
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...
1
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
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...
6
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,...
7
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...
1
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 --------- ...
2
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...
52
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.