473,396 Members | 1,968 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.

need simple join help

LRW
This has to do with mySQL 101. I know it's supposed to be super
simple, but I'm an idiot. I can't get my join to work (1st time I've
tried doing joins.)

I've read http://www.mysql.com/doc/en/JOIN.html, but I'm just not
groking it.
When I try to do the same thing, I can't "convert" one field into the
data from another.

Here's what I have. To test this concept I made two tables on a
database called db_join:

table: tbl_a
id a_name
-----------------
1 DnD
2 Spycraft
3 SG-1
4 Fading Suns
-----------------
-----------------
table: tbl_b
id game
-----------------
1 2
2 1
3 4
4 3
5 2
6 1
7 4
8 3
9 2
-----------------
-----------------

And here's the latest attempt at generating results:

$sql = 'SELECT tbl_b.id,game'
. ' FROM tbl_b'
. ' LEFT JOIN tbl_a ON game = a_name LIMIT 0, 30';
$RS = @mysql_query($sql, $connection) or die("Couldn't query: " .
mysql_error());
while ($row_RS = mysql_fetch_array($RS)) {
$block .= $row_RS['id']." - ".$row_RS['game']."<br>";
}

And the best I can do, moving fields and items around, is the
following echo of the $block:

1 - 2
2 - 1
3 - 4
4 - 3
5 - 2
6 - 1
7 - 4
8 - 3
9 - 2

What I want the final output to be is resembling this:

1 - Spycraft
2 - DnD
3 - Fading Suns
4 - SG-1
5 - Spycraft
6 - DnD
7 - Fading Suns
8 - SG-1
9 - Spycraft

What am I doing wrong? I just don't get it. If I can just get a
pointer, like "the broblem is in your WHILE statement," or "the
problem is in the SELECT part" or something like that, at least it
would narrow it down for me to figure it out.

I appreciate any advice!!
Thanks!
Liam
Jul 19 '05 #1
4 1484
"LRW" <de**@celticbear.com> wrote in message
news:3a**************************@posting.google.c om...
$sql = 'SELECT tbl_b.id,game'
. ' FROM tbl_b'
. ' LEFT JOIN tbl_a ON game = a_name LIMIT 0, 30';


I don't see anything wrong offhand, which makes me suspect that something is
wrong with the fields you are fetching themselves (i.e., they do not contain
the data they are expected to contain).

Do a structure and data dump (not of all the data, if there is a lot of it;
just enough to give us a feel of what those rows actually contain), and post
it here.

-jb
Jul 19 '05 #2
"LRW" <de**@celticbear.com> wrote in message
news:3a**************************@posting.google.c om...
$sql = 'SELECT tbl_b.id,game'
. ' FROM tbl_b'
. ' LEFT JOIN tbl_a ON game = a_name LIMIT 0, 30';


I don't see anything wrong offhand, which makes me suspect that something is
wrong with the fields you are fetching themselves (i.e., they do not contain
the data they are expected to contain).

Do a structure and data dump (not of all the data, if there is a lot of it;
just enough to give us a feel of what those rows actually contain), and post
it here.

-jb
Jul 19 '05 #3
"LRW" <de**@celticbear.com> wrote in message
news:3a**************************@posting.google.c om...
$sql = 'SELECT tbl_b.id,game'
. ' FROM tbl_b'
. ' LEFT JOIN tbl_a ON game = a_name LIMIT 0, 30';


I don't see anything wrong offhand, which makes me suspect that something is
wrong with the fields you are fetching themselves (i.e., they do not contain
the data they are expected to contain).

Do a structure and data dump (not of all the data, if there is a lot of it;
just enough to give us a feel of what those rows actually contain), and post
it here.

-jb
Jul 19 '05 #4

select tbl_b.id, tbl_b.game from tbl_b left join tbl_a on
tbl_b.game=tbl_a.a_name
Jul 20 '05 #5

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

Similar topics

0
by: LRW | last post by:
This has to do with mySQL 101. I know it's supposed to be super simple, but I'm an idiot. I can't get my join to work (1st time I've tried doing joins.) I've read...
7
by: kackson | last post by:
Hi. I created a simple view with the following statements: CREATE VIEW dbo.VIEW1 AS SELECT dbo.VIEW_ALL.ID, dbo.VIEW_ALL.Code, Another.dbo.OTHER_VIEW.Label as SpecialCode FROM ...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: Fendi Baba | last post by:
I created a person table with various fields such as Suffix, Salutation, etc, Some of these fields may not be mandatory for example suffix. In the actual table itself, I only have a field for...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
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:
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: id ------------ name
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
by: cjordan | last post by:
Hi everyone. I'm new here, and I think I've got a pretty unique problem (haven't found any solution to this anywhere else), but I'm hoping that someone here can help me. To be honest, I'm not a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.