Solved

MYSQL - left join problem

Posted on 2011-02-22
6
429 Views
Last Modified: 2012-05-11
Hi,

I am trying to create an application in php to create an SQL join, I can code the application, but I am having problems creating the string:

the SQL syntax is where the problem is: the SQL I have is:

SELECT id, username, password, rank FROM TESTTABLE1 LEFT JOIN TESTTABLE2 ON TESTTABLE1.id = TESTTABLE2.id WHERE TESTTABLE2.id > 0

the table structure is as follows:

TESTTABLE1
id username password status   rank
1  gavin    12345bbc limited  low
2  david    456456fg limited  low

TESTTABLE2
id username
1  gavin
2  david

please can someone explain where it is that I am going wrong, thanks

Gavin
0
Comment
Question by:GPB1983
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:ziycon
ID: 34951315
Try something like:

SELECT tt1.id, tt1.username, tt1.password, tt1.rank FROM testtable1 tt1, testtable2 tt2 WHERE tt1.id = tt2.id AND tt2.id > 0;
0
 

Author Comment

by:GPB1983
ID: 34951425
hiya, thanks for the quick reply,

I have tried your solution and it generates nothing what so ever.

the syntax I have used is:
SELECT TESTTABLE1.id, TESTTABLE1.username, TESTTABLE1.password, TESTTABLE1.rank FROM TESTTABLE1, TESTTABLE2 WHERE TESTTABLE1.id = TESTTABLE2.id AND tt2.id

and the DB engine is InnoDB (supports foreign keys)

where am I going wrong please?

regards, Gavin
0
 
LVL 4

Accepted Solution

by:
ziycon earned 500 total points
ID: 34951488
I'm using the below query but both this one and the first one work grand form me with the tables you have given before on mySQL.

SELECT tt1.id, tt1.username, tt1.password, tt1.rank FROM testtable1 tt1, testtable2 tt2 WHERE tt1.id = tt2.id AND tt2.id <> 0;

How are you running these queries?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:GPB1983
ID: 34951567
Hi, thanks it works, well sort of:

it gives me some results, but only the contents of testtable1, I thought that this query would basically give me the contents of both tables.

thanks,

regards, Gavin
0
 

Author Comment

by:GPB1983
ID: 34951636
false alarm mate, I saw where I was going wrong.

thanks for the help, EE needs more people like you!

top marks all round for ya!

regards, Gavin
0
 

Author Closing Comment

by:GPB1983
ID: 34951792
top marks, straight tot the point, EE needs more like him
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question