473,806 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($s ql, $connection) or die("Couldn't query: " .
mysql_error());
while ($row_RS = mysql_fetch_arr ay($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 1511
"LRW" <de**@celticbea r.com> wrote in message
news:3a******** *************** ***@posting.goo gle.com...
$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**@celticbea r.com> wrote in message
news:3a******** *************** ***@posting.goo gle.com...
$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**@celticbea r.com> wrote in message
news:3a******** *************** ***@posting.goo gle.com...
$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
381
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 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
7
1787
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 dbo.VIEW_ALL LEFT OUTER JOIN
3
10675
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 that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
2
2399
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 suffix ID where 1=Phd, 2= MD. To display all of these to the user, I created a form with an underlying query. The problem I am encountering is this, when we have an empty field, for example where ID="", the query returns nothing. How do i work around...
9
19161
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 ------------------------- SELECT * FROM ( Select x.event_date From x FULL OUTER JOIN y ON x.event_date = y.event_date
27
2863
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
1712
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
1553
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
1271
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
3227
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 DB2 guy. I'm a contractor working for a client who uses a very old AS400 to do their payroll. They're running V5R3. I'm not sure if that refers to the version of DB2 or the version of the iSeries OS that we're running. Maybe they're the same thing. As...
0
9596
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10370
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.