Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2004, 06:13 PM
burnist's Avatar
burnist burnist is offline
 
Join Date: Jul 2003
Location: Ireland
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default query question

I want to select a row from a table thats contains a list of ids which is simple enough but i want to then take each id from that row (1 per coloum) and use it to select roms in another table. I cant think of anyway to do this as there would be new colums added to the first table quite frequently.
Reply With Quote
  #2  
Old 04-10-2004, 06:35 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can do queries within queries:

e.g. SELECT * FROM table WHERE(SELECT ids FROM table2);

I believe ^^
Reply With Quote
  #3  
Old 04-10-2004, 07:12 PM
burnist's Avatar
burnist burnist is offline
 
Join Date: Jul 2003
Location: Ireland
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$useritemsquery $DB_site->query("SELECT id,name,icon FROM items WHERE id =('SELECT * FROM items_users WHERE userid=$bbuserinfo[userid]') ORDER BY id ASC");
while(
$useritems $DB_site->fetch_array($useritemsquery)){
eval(
"\$showusersitem .= \"".fetch_template("itemshop_showuseritems")."\";");

Thats what i've go so far and i think what you ment works but i think it joins all the id's together into one big id and then the first query cant find the row and wont return it so the eval never happens
Reply With Quote
  #4  
Old 04-10-2004, 07:18 PM
Christine's Avatar
Christine Christine is offline
 
Join Date: Oct 2001
Location: PA
Posts: 472
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
You can do queries within queries:

e.g. SELECT * FROM table WHERE(SELECT ids FROM table2);

I believe ^^
Dean,

I think that isn't available until MySQL 5 (or is it 4.1)?
Reply With Quote
  #5  
Old 04-10-2004, 07:34 PM
burnist's Avatar
burnist burnist is offline
 
Join Date: Jul 2003
Location: Ireland
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

^ crap i only run 4.0.18
Reply With Quote
  #6  
Old 04-11-2004, 01:26 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm pretty sure I read it in the mysql 4 manual
Reply With Quote
  #7  
Old 04-11-2004, 01:51 PM
Christine's Avatar
Christine Christine is offline
 
Join Date: Oct 2001
Location: PA
Posts: 472
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gotcha.

I had to dig it back up, because I didn't recall the specifics but it stuck out to me that 'I can't do this yet'.

Apparently, it isn't a matter of can't, it is a matter of how (and that is what changes in 4.1)
Quote:
For MySQL versions prior to 4.1, most subqueries can be successfully rewritten using joins and other methods.
http://dev.mysql.com/doc/mysql/en/Subqueries.html

http://dev.mysql.com/doc/mysql/en/Re...ubqueries.html

Glad I saw this thread!!
Reply With Quote
  #8  
Old 04-11-2004, 03:42 PM
burnist's Avatar
burnist burnist is offline
 
Join Date: Jul 2003
Location: Ireland
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So basicly im looking for something like this ??

[sql]
$DB_site->query("SELECT id,name,icon FROM items
LEFT JOIN items_users ON items.id=items_users.*
WHERE items_users.userid IS $bbuserinfo[userid]; ORDER BY items.id ASC");
[/sql]
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:19 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04202 seconds
  • Memory Usage 2,231KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete