vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL the same field from two different rows? (https://vborg.vbsupport.ru/showthread.php?t=143932)

cashpath 04-03-2007 02:14 PM

MySQL the same field from two different rows?
 
Is it possible to run a MySQL query that will pull the same field but from two different rows? Using two different WHERE clauses? Could someone show me an example of how that would be done?

bluesoul 04-03-2007 02:20 PM

SELECT fieldid FROM table WHERE fieldid IN (1,4,7)

Where 1,4, and 7 are the different rows you are looking for.

cashpath 04-03-2007 02:32 PM

ok lets say this is the code

Code:

SELECT rank FROM table WHERE week=5
But I also want to SELECT rank FROM table WHERE week=4 too and have it in the same row on the result.

bluesoul 04-03-2007 07:29 PM

I'm not sure I follow, you can do:
[sql]SELECT rank FROM [table] WHERE week IN(4,5);[/sql]
And they'll show up in their respective rows. Putting them side by side in the same row would be a formatting thing, more cosmetic than anything. I think you'll be better off formatting your results through PHP or whatever language you're using.

cashpath 04-03-2007 08:38 PM

Ok :) so the answer is no...

Thanks.

Michael Biddle 04-03-2007 08:44 PM

Not sure exactly what you mean?

if you want two differnt ones, run 2 seperate quieres.

ElfMage 04-03-2007 09:44 PM

You could do this by using a cross join (also referred to as table product):

Code:

SELECT t1.rank, t2.rank FROM table t1, table t2 WHERE t1.week=5 AND t2.week=4

cashpath 04-03-2007 10:17 PM

Ok thanks Elfmage..


Quote:

Not sure exactly what you mean?

if you want two differnt ones, run 2 seperate quieres.
I was trying to eliminate the amount of queries I was running.

Michael Biddle 04-04-2007 03:36 AM

you could also do a left join for this then


All times are GMT. The time now is 05:50 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01547 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete