• 0

Problem with Query


Question

ok here's my wquestion about making amysql query that i cant resolve it seems to be very easy but i cant resolve it.. so thats why i ask for help here guys, hope you can help me!

I have two tables this is the structure:

TABLE1:

-uid

-name

-surname

TABLE2:

- uid

- site

- url

Well table explanation Table number 1 ahs the necesary info of an user. Table number 2 has the user id and his web pages (can be more than one), so the uid in table two can have duplicates...

well my problem is that im filling a select box with the name of the user but i need to fill it with the names that are not in the table two.. for example if i have already the user number 1 in the table two the select box only will have from 2 to n, it shouldnt shown user number 1.. this is the query im trying to use but it doesnt work

$sql = "SELECT TABLE1.uid
  ,TABLE1.name
	FROM TABLE1,TABLE2
	WHERE TABLE1.uid <> TABLE2.uid
	";

so thats the query and donest work for me.. the only way it works is if i have only one user id in the table two but if i have more than one uid in table 2 the query retrieve alll the records

Hope you can help guys!!

Thanks!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Well, first off, I'd rename those tables. They're not descriptive at all! Table1 should be "members" or "users". Table2 should be "sites" or something. Don't confuse yourself. You can name tables for a reason ;). Also, you NEED a primary key on your second table. Put another field in the front of the table called "site_id" or something. It'll be the id for each site, with the uid linked to it. It'll make coding a WHOLE lot easier ;)

Ok, onto the query. It doesn't work if you look at it simply. You've got two tables, you're select data where 1.uid is not equal to 2.uid. MySQL is saying "Wait, what uid's are you talking about?" You're selecting on abirtrary rows. I'm kind of confused myself. Can you explain better what you're trying to do? What is this select box for? There might be another way of going about this :)

Link to comment
Share on other sites

  • 0

well in a select box i need to show user from my database... from the user table but i want to show only the users that are not in the oher table, in this example TABLE2 mentioned above, so if i have a user id (uid) in the TABLE2 i dont want to show them in the select box..... for example:

TABLE1

- User1

- User2

- User3

- User4

and in TABLE2

- User3

- User4

So my select box i want to show only User1 and USer2 because 3 and 4 are already in the other table...

I used those table names just for this example.. jejej.. dont worry i have descriptives names on my DB? ;)

Greets!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.