Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Question Unanswered: 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 Attached Thumbnails Picture 11.png  
    Last edited by wilantara; 11-18-09 at 11:11.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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.

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    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.

  4. #4
    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,,,,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •