Solved

MYSQL - left join problem

Posted on 2011-02-22
6
431 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

622 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