» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2006, 05:00 AM
HParsew HParsew is offline
Junior Member
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
HParsew is on a distinguished road
Default to write long select query??

hi, i want to write 1 long select query. i have 3 tables : a1 (id,name) , a2(id,name) , a3(a1_id,a2_id). so i give to procedure 2 variables (different a2_id), and i need to

select these a1 which have same a2_id. so 2 diferent a2 may have same a1

example: a1 table:
name id
first 1
second 2
third 3

a2 table looks:
name id
red 2
blue 3
green 4

a3 tables looks
a1_id a2_id
1 2
2 3
2 4
so if i give a2_id = 3(red) and a2_id = 4(blue) results must be a1_id = 2(second)
Please help me folks.
thanx! -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 11-15-2006, 05:02 AM
rian rian is offline
Senior Member
 
Join Date: Jul 2006
Posts: 135
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 16
rian is on a distinguished road
Default

To retrieve a1_ids for which there exists an a1_a2.a2_id value of 3 AND and an a1_a2.a2_id of 4, try

SELECT a1_id
FROM a1_a2 AS 1
JOIN a1_a2 AS 2 USING (a1_id)
WHERE a2_id=3 OR a2_id=4
HAVING COUNT(a2_id)>0; -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT Query?? Dblack MySQL Forums 1 10-17-2006 04:29 AM
nested select statement. PowerX MySQL Forums 1 09-30-2006 06:45 AM
Mysql_affected_rows() isn't working on a delete query? zizu PHP Programming and Tips 1 08-26-2006 02:05 PM
Error in select statement speedy PHP Programming and Tips 1 08-19-2006 09:32 AM
Starting in the business? Time to write a Business Plan ! WEBDOMAIN.com Web Hosting Industry 0 07-28-2006 07:27 PM


All times are GMT. The time now is 05:14 PM.