If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > please anyone help me to using subqueries in mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-09, 10:05
wilantara wilantara is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
Question please anyone help me to using subqueries in mysql

hi,,,,
please anyone can help me and tell me what's wrong in my query,,,

first, this is my query:
select id, F1, F6 from jos_ckforms_1 where id=101 or F6=101 or
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101) or
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))
or F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101)));

i have tested my query above, it works!!!

than,,,
i try to run this query(second query):
SELECT id, F1, F6 from jos_ckforms_1 where id=101 OR F6=101 OR
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101) OR
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))
OR F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))) OR
F6 = any(select id from 'jos_ckforms_1' WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))));

but it did'nt work,
whereas i just add:
OR
F6 = any(select id from 'jos_ckforms_1' WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))))
to first query,,,,

ohhh,,, i became crazy,,,,
what's wrong in my second query?
please anyone explain to me,,,,
"i attached an error message picture"
please,,,,
Attached Thumbnails
please anyone help me to using subqueries in mysql-picture-11.png  

Last edited by wilantara; 11-18-09 at 10:11.
Reply With Quote
  #2 (permalink)  
Old 11-18-09, 10:21
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Creating your own syntax is fun but tends to lead to errors. Try looking at the manual for MySQL to see the syntax allowed in selects. What does the ANY() command do? Why do you say WHERE but then have no where condition? Can you put into English what you expected the SQL to do? You just seem to be endlessly checking that field id or F6 is equal to 101. Giving decent names to your tables and fields will also improve the readability.
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 11:29
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
also, since everything is ORed together, I hope your table never gets really big as you will more than likely being scanning every row of the table.
Reply With Quote
  #4 (permalink)  
Old 11-19-09, 10:29
wilantara wilantara is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
thanks mike_bike_kite, thanks dav1mo
i've got a solution,,,
this is my query:
select id , F1 , F6 from jos_ckforms_1 where id=101 or F6=101 or
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101) or
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))
or F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101)
or
F6 = any(select id from `jos_ckforms_1` WHERE
F6 = any(select id FROM `jos_ckforms_1` WHERE F6=101))));

this query just for getting information where F6 is referal_id and 101 is a lone key id to get others id.
again, thanks all,,,,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On