Jump to content

[SOLVED] mySQL 4 query unique results with a join?


Recommended Posts

hello,

 

I am having trouble getting unique results returned on a query

 

code looks like:

 

		$query = "SELECT distinct c.id, c.english"
			. "\n FROM bil_cities AS c"
//				. "\n JOIN bil_msg_sent AS m ON (m.locid = l.id)"
//				. "\n JOIN bil_location AS l ON (c.id = l.city_id)"
			. "\n JOIN bil_location AS l"
			. "\n WHERE c.id = $val"
//				. "\n AND c.id = l.city_id"
//				. "\n GROUP BY c.english"
			. "\n ORDER BY c.english";
	$result = mysql_query($query);

 

with the different attempts I've made so far  I get one of 2 results,

 

1: no results

2: 9 references to the same entry

 

any ideas?

for future reference the code ended up looking like:

 

		$query = "SELECT c.id, c.english"
			. "\n FROM bil_cities AS c"
			. "\n JOIN bil_location AS l"
			. "\n WHERE c.state_id = $val"
			. "\n AND c.id = l.city_id"
			. "\n ORDER BY c.english";
	$result = mysql_query($query);

 

solved this one when going to clarify my question,

 

in this case $val is the ID from a table of US states

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.