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

Problems with JOINing


Folks,

I've not done a join before... and I need some help - I believe my
problem is because I am attempting to join two tables which both have a
hash column in common, however their names in the two tables are different.

Thus: address.hash=hpg.house_hash

I need a select that will allow me to select

address.business_name
address.postcode
hpg.group_name

WHERE address.address_type='H'
AND address.hash=hpg.house_hash
AND address.hash="myhash"

I believe I require a JOIN because I'm not guaranteed to have a value
returned for hpg.group_name for every record.

Can someone help me with this? What I have tried so far is giving me
errors in MySQL Query Browser ("Not unique table/alias: 'hpg'") and I
guess this is because it expects a table cell name in address to be
found also in hpg.... true?

Help via the newsgroup (so all can learn) would be greatly appreciated...

Randell D.
Jul 23 '05 #1
2 1154

"Randell D." <ab***@shaw.ca> wrote
I've not done a join before... and I need some help - I believe my problem
is because I am attempting to join two tables which both have a hash
column in common, however their names in the two tables are different.

Thus: address.hash=hpg.house_hash

I need a select that will allow me to select

address.business_name
address.postcode
hpg.group_name

WHERE address.address_type='H'
AND address.hash=hpg.house_hash
AND address.hash="myhash"


Try:

select address.business_name,
address.postcode,
hpg.group_name
FROM address INNER JOIN hpg on address.hash=hpg.house_hash
WHERE address.address_type='H'
AND address.hash="myhash"

If you want a result even if there is no corresponding hpg row, then change
the inner join to a left join. In this case hpg.group_name will come back
as NULL.

It is a Good Thing to get into the habit of explicitly defining your joins
using INNER JOIN, LEFT JOIN, and the like.
Jul 23 '05 #2
Dan Stumpus wrote:
"Randell D." <ab***@shaw.ca> wrote

I've not done a join before... and I need some help - I believe my problem
is because I am attempting to join two tables which both have a hash
column in common, however their names in the two tables are different.

Thus: address.hash=hpg.house_hash

I need a select that will allow me to select

address.business_name
address.postcode
hpg.group_name

WHERE address.address_type='H'
AND address.hash=hpg.house_hash
AND address.hash="myhash"

Try:

select address.business_name,
address.postcode,
hpg.group_name
FROM address INNER JOIN hpg on address.hash=hpg.house_hash
WHERE address.address_type='H'
AND address.hash="myhash"

If you want a result even if there is no corresponding hpg row, then change
the inner join to a left join. In this case hpg.group_name will come back
as NULL.

It is a Good Thing to get into the habit of explicitly defining your joins
using INNER JOIN, LEFT JOIN, and the like.


Hi,

For some reason my mozilla news client wouldn't refresh the latest
entries for mailing.database.mysql so I couldn't see my OP. Other ng I
subscribe to were fine... I knew the mysql world would have had more to
say in 18hours than I had seen so by unsubscribing, and re-subscribeing,
an extra hundred or so posts were delivered...

However - because I couldn't see my original post (or your reply) this
morning, I slept on the problem and came up with an alternative solution
- My problem does relate to columns in the hpg table that would be
returned as null (I've been reading more and more in to JOINs since my
OP). Since I couldn't work the syntax out, I gave the column a default
value of 0 as opposed to allowing NULL and this seems to do the trick.

I'm going to play with your solution though as I do think my lack of
understanding of JOINs is a weakness in my skillset and coding.

Thanks for the help... I will play with the code and see if it can help
my understanding...

randelld
Jul 23 '05 #3

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

Similar topics

0
by: daniel.poelzleithner | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, i wrote a module for ctrlproxy which embedds python and provides an api that ctrlproxy is scriptable. Every script is started in an own...
3
by: Carlos Ribeiro | last post by:
As a side track of my latest investigations, I began to rely heavily on generators for some stuff where I would previsouly use a more conventional approach. Whenever I need to process a list, I'm...
5
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
5
by: Eddie | last post by:
I have an Access database that tracks project information. The database is very simple, except for 1 small aspect. Some background: 4 Tables - Project information, Employees, activity and pay...
9
by: Eric Sabine | last post by:
Can someone give me a practical example of why I would join threads? I am assuming that you would typically join a background thread with the UI thread and not a background to a background, but...
11
by: Ben Marklein | last post by:
I'm trying to migrate from 7.2 to 7.4.1 via pg_dump/pg_restore and have encountered a couple of problems: 1) Index creation on a table fails: db=# CREATE UNIQUE INDEX person_info_username_ix...
3
by: Ryan Riehle | last post by:
Hi All! Trying to upgrade to Apache 2.0.49 and getting compile errors related to mod_auth_pgsql, any clue?: make: Entering directory `/usr/src/httpd-2.0.49'...
2
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT...
1
by: yuva | last post by:
"Thank you for this amazing program. Within a weekend, my team increased with 50 new people joining. Every time I logged on there was a new affiliate. Absolutely amazing. " S. Horvath SOUTH AFRICA...
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: 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
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...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.