473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JOIN table results w/MySQL

I have a query with a simple JOIN.

For example:

SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.

How can this be accomplished?

Thanks.
Jul 17 '05 #1
8 4023
Xenophobe wrote:
I have a query with a simple JOIN.

For example:

SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.

How can this be accomplished?

Thanks.


Hi Xenophobe

what about using the columnnames instead of * ????
Didn't anybody tell you * means 'return all' in SQL?
I don't want to insult you, but I think you should do a tutorial on SQL
first, before doing more coding.
Here is a good one for starters: http://www.w3schools.com/sql/default.asp

Regards,
Erwin Moller
Jul 17 '05 #2
I noticed that Message-ID: <c70Mc.147430$IQ4.55392@attbi_s02> from
Xenophobe contained the following:
The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.

How can this be accomplished?

Replace the * with whatever fields you want.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
Try the following:

SELECT Companies.* from Companies .....

This way you are specifying all fields from the Companies table which
ignores all other tables.

HTH.

--
Tony Marston

http://www.tonymarston.net

"Xenophobe" <xe*******@planetx.com> wrote in message
news:c70Mc.147430$IQ4.55392@attbi_s02...
I have a query with a simple JOIN.

For example:

SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.

How can this be accomplished?

Thanks.

Jul 17 '05 #4
.oO(Xenophobe)
SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.


This is one of the reasons why you should avoid SELECT * (except for
short tests etc.) and list all requested columns explicitly.

Micha
Jul 17 '05 #5
Sigh... I know asterisk means "all". I usually do specify the fields, but in
this case that's everything in my "Companies" table. For small tables with a
limited number of rows sometimes asterisk is easier.

OK, the winner is Tony.

Specifying "Companies" before the asterisk did the trick.

Thanks.

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:cd*******************@news.demon.co.uk...
Try the following:

SELECT Companies.* from Companies .....

This way you are specifying all fields from the Companies table which
ignores all other tables.

HTH.

--
Tony Marston

http://www.tonymarston.net

"Xenophobe" <xe*******@planetx.com> wrote in message
news:c70Mc.147430$IQ4.55392@attbi_s02...
I have a query with a simple JOIN.

For example:

SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would like all fields from Companies only.

How can this be accomplished?

Thanks.


Jul 17 '05 #6
I noticed that Message-ID: <JdaMc.12152$eM2.6632@attbi_s51> from
Xenophobe contained the following:
OK, the winner is Tony.


Why? Tony's advice, though correct and specific, would not help you gain
fuller understanding.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:2k********************************@4ax.com...
I noticed that Message-ID: <JdaMc.12152$eM2.6632@attbi_s51> from
Xenophobe contained the following:
OK, the winner is Tony.


Why? Tony's advice, though correct and specific, would not help you gain
fuller understanding.


Because it answered the question that was asked, but all other response
presumed a lesson was needed and assume a pedantic tone.

Tony provided the same answer I would have provided, but I checked to see if
that answer was already made available. I might have added a note to use
correlation names to reduce the clutter.

- Virgil
Jul 17 '05 #8
Virgil Green wrote:
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:2k********************************@4ax.com...
I noticed that Message-ID: <JdaMc.12152$eM2.6632@attbi_s51> from
Xenophobe contained the following:
>OK, the winner is Tony.
Why? Tony's advice, though correct and specific, would not help you gain
fuller understanding.


Because it answered the question that was asked, but all other response
presumed a lesson was needed and assume a pedantic tone.


<snip>

- Virgil


Hi Virgil,

I understand your response, but would like to add that OP clearly showed he
needs some more SQL lessons.
Only getting answers is often less rewarding than somebody who takes the
time to tell you what you are missing in your knowledge.
In the case of the original question I think the advise he should do more
SQL training before proceding is worth more than the actual answer.
IMHO.

I know I was corrected sometimes in the past (especially with Java) and
though it irritated me a little at the time, I was gratefull afterwards.
Why?
Because experienced people could spot the hole in my understanding by just
reading the question. They told me to study this or that first. Most of the
time they were right.
Who cares about pedantic tones anyway? I am here to learn and help others,
not to socialize.

Regards,
Erwin Moller
Jul 17 '05 #9

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

Similar topics

6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
8
by: red | last post by:
This is a simple join but I am having trouble with it. I feel like such an idiot. I start with this select statement, which works fine: $query = "SELECT a.auction, a.winner, b.id FROM...
0
by: Doug Reese | last post by:
hello, i have what seems to me a very common operation i'm performing. i need to find the balance on an invoice. i was not having any problems until the production server was upgraded to mysql...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
9
by: Dave M | last post by:
All I've got a database that keeps track of sales of widgets. Each company that belongs to my organiztion is to report their widget sales or no sales every month. There are several different...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the following: create table A ( uniqueId int not...
5
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
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
7
by: steve | last post by:
Can you join two tables across different servers in mySQL, or am I dreaming of Oracle? -- Posted using the http://www.dbforumz.com interface, at author's request Articles individually checked...
2
by: terence.parker | last post by:
I am often faced with the dilemma of whether to use a JOIN query across three tables in order to grab a bunch of results - or whether to create another table to represent what I want. The latter is...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.