Best way to select several mysql table rows at random?
What is the best and quickest way to have one form button select multiple rows from a table with complete randomness?
Can you also offer some explanation (or link to a good tutorial)- I am a beginner in myql and php.
thanks
p.s. the id column in my table is auto incrementing and has some gaps (due to deletions of records). I do not want any of those gaps to be chosen at random (can they?).
What do you have so far? How many rows will your table have and how many do you want to randomize? To produce random result without filter will put a strain on your server, especially if you have a lot of rows and you get a lot of server requests (pageloads). To randomize the results you basically have to recreate the table dynamically then output the result as an array. Again, this will put a huge load on your server. This may sound silly and ridiculously obvious, but have you tried searching the obvious term on google for MySQL random? There are millions of articles that describe the subject. Many first page results will show you exactly what you need to do. Try searching first then if you have trouble ask here, referencing the article you followed by first searching google.
best,
Shocker
Similar Messages
-
Best way to select from 2 tables, based on sum from detail table
I have a "customer order line detail" table from which I want to report
Order Number
Customer Number
Part Number
Line Value { which is Unit Qty * (Unit price - discount%) }
But only for orders which are above £1500.
And lines which are not "Cancelled"
I have access to an API which returns the total order value for the order.
I am currently using this in my criteria, eg:
select order_no, customer_no, part_no, round(unit_qty *(unit_price - unit_price *(discount/100)),2) Line_value
from customer_detail
where
status != 'Cancelled'
and
Customer_Order_API.Get_Total_Sale_Price__(order_no)>=1500
The API contains the following:
SELECT SUM(ROUND((qty * price_conv_factor * unit_price), rounding_) -
ROUND((qty * price_conv_factor * unit_price) -
((qty * price_conv_factor * unit_price) * ((1 - discount / 100) * (1 - order_discount / 100))), 2))
FROM customer_detail
WHERE order_no = order_no_
AND state != 'Cancelled'
AND line_item_no <= 0
(that uses a price conversion factor that I don't use, since it's always 1)
My query runs so slowly, because it is getting the order value for every line of the order, is it possible to improve?
ThanksThanks for the suggestion, it was close to what I needed.
I ended up with this:
select order_no, name, ref_id, c_salesman_sub_division, line_value, catalog_desc
from
(SELECT coj.customer_no, coj.order_no, ifsapp.customer_info_api.GET_NAME(customer_no) name, coj.ref_id,
coj.c_salesman_sub_division, ROUND((coj.buy_qty_due * coj.
price_conv_factor) * coj.sale_unit_price, 2) - ROUND((coj.buy_qty_due *
coj.price_conv_factor) * coj.sale_unit_price - ((coj.buy_qty_due * coj.
price_conv_factor) * coj.sale_unit_price) * ((1 - coj.discount / 100) *
(1 - coj.order_discount / 100)), 2) line_value, coj.catalog_desc,
SUM( ROUND((coj.buy_qty_due * coj.
price_conv_factor) * coj.sale_unit_price, 2) - ROUND((coj.buy_qty_due *
coj.price_conv_factor) * coj.sale_unit_price - ((coj.buy_qty_due * coj.
price_conv_factor) * coj.sale_unit_price) * ((1 - coj.discount / 100) *
(1 - coj.order_discount / 100)), 2)) OVER (PARTITION BY Coj.ORDER_NO) AS SUM_ORDER
FROM ifsapp.customer_order_join coj
WHERE coj.order_no = coj.order_no
AND TRUNC(coj.date_entered) = NVL(TO_DATE('25/01/2007', 'DD/MM/YYYY'),
TRUNC(SYSDATE))
AND coj.authorize_code = 'UKMEDM'
AND coj.line_item_no >= 0
AND coj.ref_id <> 'SAMP'
AND coj.state <> 'Cancelled'
where sum_order >=1500
ORDER BY ref_id, c_salesman_sub_division, customer_no, order_no
/[pre]
But I have realised the problem with this. Not sure if I made it clear, to myself even, but I need to include
order lines added on a particular day (that are not cancelled)
for orders which total >= £1500.
If one line of an order is added for £900 but the rest of the order is £2000 then that line should be shown.
My SQL only shows lines added for the day >= 1500. -
Best way to deal with Mutating table exception with Row Level Triggers
Hello,
It seems to be that the best way to deal with Mutating Table exception(s) is to have to put all the trigger code in a package & use it in conjunction with a Statement level trigger .
This sounds quite cumbersome to me . I wonder is there any alternative to dealing with Mutating table exceptions ?
With RegardsAskTom has a good article about this,
http://asktom.oracle.com/tkyte/Mutate/index.html -
Best way to outer join a table that is doing a sub query
RDBMS : 11.1.0.7.0
Hello,
What is the best way to outer join a table that is doing a sub query? This is a common scenario in EBS for the date tracked tables.
SELECT papf.full_name, fu.description
FROM fnd_user fu
,per_all_people_f papf
WHERE fu.user_id = 1772
AND fu.employee_id = papf.person_id(+)
AND papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
FROM per_all_people_f per1
WHERE per1.person_id = papf.person_id)Output:
No output produced because the outer join cannot be done on the sub queryIn this case I did a query in the FROM clause. Is this my best option?
SELECT papf.full_name, fu.description
FROM fnd_user fu
,(SELECT full_name, person_id
FROM per_all_people_f papf
WHERE papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
FROM per_all_people_f per1
WHERE per1.person_id = papf.person_id)) papf
WHERE fu.user_id = 1772
AND fu.employee_id = papf.person_id(+)Output:
FULL_NAME DESCRIPTION
{null} John DoeThanks,
--JohnnieHi,
BrendanP wrote:
... See the adjacent thread for the other with Row_Number().Do you mean {message:id=10564772} ? Which threads are adjacent is always changing. Post a link.
I think RANK suits the requirements better than ROW_NUMBER:
WITH all_matches AS
SELECT papf.full_name
, fu.description
, RANK () OVER ( PARTITION BY papf.person_id
ORDER BY papf.effective_start_date DESC
) AS r_num
FROM fnd_user fu
LEFT OUTER JOIN per_all_people_f papf ON fu.employee_id = papf.person_id
WHERE fu.user_id = 1772
SELECT full_name
, description
FROM all_matches
WHERE r_num = 1
Johnnie: I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
See the forum FAQ {message:id=9360002} -
Best way to organize several versions of Photoshop Elements to conserve disk space?
I have Elements 9, 11, and now Version 12. I am wondering if I should import into Version 12's Organizer all of my previous photo files, then delete or uninstall the older versions of PhotoShop Elements?
Currently running Windows 7 - 64 bit with latest SP installed. I would like to try and keep the hard disk storage fairly lean, and can't help but wonder about the space that is being taken up by having all of these versions of Elements installed! Any advice would be welcome. Thanks for your replies and insights!
BrokenBellThank you so much for your input! I sometimes feel that I must be increditable stupid as I try to get BOTH organized but also learn how to use all of the features found in Photoshop Elements. Part of the reason that I say this, is because I have always been pressed for time, so I try & do one most pressing thing, that usually doesn't turn out quite like it was described it would or could be, and then I'm off to take care of more pressing issues, and don't get back to trying it after days or weeks have passed, so its kinda of like starting all over again.
Again, thanks for your reply and input!
Sincerely,
Clyde [email protected]
Date: Tue, 14 Jan 2014 14:31:09 -0800
From: [email protected]
To: [email protected]
Subject: Best way to organize several versions of Photoshop Elements to conserve disk space?
Re: Best way to organize several versions of Photoshop Elements to conserve disk space?
created by nealeh in Photoshop Elements - View the full discussion
The organizer does not store your photos, only links to their locations on the hard disk. So all your different versions will be looking at the same image file, so no duplication of the photos themselves.
If you find yourself using features in 9 or 11 that were removed in later versions (e.g. interactive photomerge, magic extractor, lighting effects etc ...) I'd be inclined to leave them installed unless you are critically short of disk space.
Cheers,
Neale
Insanity is hereditary, you get it from your children
If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.
Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6013170#6013170
Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6013170#6013170
To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6013170#6013170. In the Actions box on the right, click the Stop Email Notifications link.
Start a new discussion in Photoshop Elements at Adobe Community
For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0. -
What is the best way of selecting 99 colums from a table with 100 colums?
Hi All,
Suppose in a table T, I have 100 colums .I want to select 99 columns.So what is the best way to do the same?
Anyone Help!
Thanx in advance.
PiyushTry this
SQL> ed
Wrote file afiedt.buf
1 select column_name ||',
2 ' from user_tab_columns
3 where
4 table_name = 'EMP'
5* and column_name not like 'EMPNO'
SQL> /
COLUMN_NAME||','
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO,
7 rows selected.
SQL> -
Best way to update an OLTP table ?
Hi,
We have an OLTP table with huge data.
We need to update a status column from 'N' to 'Y' for almost 70% of rows based on some condition.
This table may be accessed by hundreds of sessions at a time.
So, what is the best way to do the same.
Rgds,
Rupif someone is using the table, ddl cannot be done (or at least you would have to wait maybe a long time)
quick test...
SQL> create table bank
2 (id number primary key
3 ,acc number
4 ,ind varchar2(1)
5 )
6 /
Table created.
SQL> insert into bank
2 select rownum
3 , rownum * 10
4 , 'N'
5 from all_objects
6 where rownum <= 10
7 /
10 rows created.
SQL> commit;
Commit complete.
SQL> update bank
2 set acc = -10
3 where id = 10
4 /
1 row updated.new session
SQL> alter table bank
2 add new_ind varchar2(1)
3 /
alter table bank
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specifiedwell, not a long time... but anyway you can't do ddl while someone is working on the table. -
Best way to select distinct values based on another column?
I have a table with three columns: id (NUMBER), data_dt (DATE), and data_value (NUMBER).
There is a primary key on id and data_dt.
I want to select the record with the latest data_dt for each unique id.
What is the best way to do this?
I have three different methods, but there may be something I am missing.
First:
SELECT *
FROM
SELECT id, data_dt, data_value,
FIRST_VALUE(data_dt)
OVER (PARTITION BY id ORDER BY data_dt DESC) AS last_data_dt
FROM the_table
WHERE data_dt = last_data_dt;(I use ORDER BY...DESC instead of just ORDER BY so I don't need the ROWS BETWEEN clause)
Second:
SELECT t1.*
FROM the_table t1
JOIN
SELECT id, MAX(data_dt) AS last_data_dt
FROM the_table
GROUP BY id
) t2 ON (t2.id = t1.id AND t2.data_dt = t1.data_dt);Third:
SELECT t1.*
FROM the_table t1
WHERE t1.data_dt =
SELECT MAX(t2.data_dt)
FROM the_table t2
WHERE t2.id = t1.id
);-- DonHi,
There are more possible scenario's, for example:
select t1.*
from the_table t1
where not exists ( select null
from the_table t2
and t2.data_dt > t1.data_dt
What is the best way to do this?Only you can tell:
Test all scenario's, check the execution plans, set timing on and pick the best/fastest one ;-)
If it's not clear, please post the execution plans here. -
Best way to insert in a table througth a database link
Hi all,
i have two databases (oracle 10g, windows 2003 server)
Database A and Database B
i need to insert data in a table (Table_A) that lives in database A
The data i have to insert is in a table that lives a database B
I have a database link from database B to database A
so, connected to database B, i'm trying the following :
insert into table_a@database_link_to_A
select col1
from table_b
where col1 is not null
This query is taking forever, and i have to cancel it.
I'd like to hear from your experience. Wich is the best way to accomplish this task ?
Best Regards
Rui Madaleno
NOTE: I forgot to mencion that Table_A does not have any trigger or indexes.
Edited by: ruival on Jan 20, 2010 3:51 PMTry this:
insert /*+ append */ into table_a@database_link_to_A select col1 from table_b where col1 is not nullOr
Sqlplus COPY another option.
[http://www.praetoriate.com/oracle_tips_dm_sqlplus_copy.htm]
HTH
-Anantha -
How is the best way to manage the stats table?
Hello!
I have the Integration 2.1 working with an Oracle 8.1.7 db. I noticed that the table
STATS is growing pretty fast.
How is the best way to manage this table?... I haven't found something related with
this issue in the documentation, but at least I want to know how to safely delete
records from this table.
For example, if I know the minimal time I have to keep in the table, is quite simple
to create a shell script and/or Oracle pl/sql job to trim the table.
I hope somebody can help me!!!!
Thank you!
Ulises SandovalWrite an app people want to buy and rate highly.
-
Hi
My company just started a new project that implies migrating every hour operational data from a mysql database located at another company to our main DB (oracle10gR2). Between these two DB, we have an oracle XE DB which contains the database links to both DB and a procedure to get (from mysql) and insert (oracle10g) the values. What happens is that in the mysql DB, the values have decimals and, when i select the table in oracle, i only see integer values (no decimals). Here is an example of the select i use:
SELECT "v_hour", "v_date", "v_type", "v_tabstamp","v_value"
FROM "tab1"@mysql;
How can i work around this problem?
Many thanks!Maybe just a HS_LANGUAGE setting issue.
You could try that:
1a) in the gateway init file, please set HS_LANGUAGE=GERMAN_GERMANY.WE8ISO8859P1
2a) now open a new SQL*Plus session ans select from your table using the gateway based database link
=> if the values are now including the decimal part then your foreign database is set up to use a comma as the decimal separator and you have to make sure that the HS_LANGUAGE contains a territory that uses as decimal separator a comma.
If you still do not get the decimal values, then change it to:
1b) HS_LANGUAGE=american_america.we8iso8859P1
2b) Make sure you start again a new SQL*Plus session (the gateway init file is only read when you use the database link in your session for the first time (or explicit closed it before). Select again from your table.
=> is the decimal part now visible?
More details can be found in the gateway note: Gateway and Decimal Digits(Doc ID 1453148.1) available from My Oracle Support portal.
- Klaus -
Best way to connect two fact tables when no conformed dimension exists
Can anyone please elaborate how would I connect two fact table without any conformed dimension. Let say FACTA, FACTB. FACTB is related to a dimension "StatusDim". I want to select the count of all FACTA item which are related to FACTB items with
a particular status. I have found the following article but just wondering whether it is the best practise to connect two fact tables directly.
http://bifuture.blogspot.com/2011/11/ssas-selecting-facts-with-reference.html
Thank youHi Ahsan,
After read the blog you posted, I think it's a pretty good solution to create a view in the relational database or a named query in the Data Source View containing as the the columns in FACTA and FACTB. Then build a dimension from it, setting the "Null processing"
property (you have to click the "plus" two times for the "Key Columns" property of the attribute in BIDS to access this property) to "UnknownMember". And then use this dimension for the many-to-many relationship. Dimensions from FactA can benefit of the reference
relationship between FactA and FactB and therefore a powerful solution it is.
Regards,
Charlie Liao
If you have any feedback on our support, please click
here.
Charlie Liao
TechNet Community Support -
Best way to select BOTH notes and midi CC?
Hello everyone,
I'm trying to figure out the quickest, most efficient way to select and move both notes and MIDI CC's at the same time in the matrix editor w/ hyperview. The only way I've been able to accomplish this is to shift-drag around both parts, but this takes time time as you have to do it TWICE; once for the notes and once for the midi cc's. Unfortunately "select all" or "select within locators" does not select midi cc's.
What is the best way to deal with midi cc's? I wish there was some way to select and "lock" them to midi notes and when you drag the notes, it drags the midi cc as well, similar to how FCP locks audio and video together. Do other programs allow this functionality?
Thanks once again for any help/tips you can provide!Functions > Include Non-note MIDI Events, but unfortunately there is no key command for it.
I prefer to have a screenset with an Event List open, so I can Command-~ to the event list, Command-A, and then drag in the Matrix. Or double click the fist note in the Event List and enter a new Bar# for its position. Or Command-C and Command-V, then enter a new number for a copy...
...you get the idea. -
Best way to load data in table from combination of Table and flat file?
Hi All,
Could you please share your thoughts on best way of achieving this objective -
Flat File - 15 Million records (Field A,B,C)
Table A - 15 Million records ( Field A,D)
Objective -
Load Field A,B,C,D in Table B from Flat file and Table A.
Data can be loaded from flat file in Table B then updated from Table A but this update operation is taking lot of time. (Intermediate Commit, Bulk operations already tried)
Regards,
Dark KnightEnvironment -
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Tables are analyzed.
Indexes are their.
Update statement using the index.
Data is close to 200 MB.
I am interested in knowing if there are alternate ways of doing this, other than conventional way of loading data then updating it. -
Advice for best way to do this dynamic table -please help
Hello, I would like to create paginated recordsets without
specifying the filename over and over again. For example, if I have
folders of pictures with sequential filenames, is there anyway to
get around manually entering them in the database? If not, what is
the best way to go about doing this because I will have a great
number of these "books" to create. Maybe there is a way to just
auto-enumerate a 1.jpg, 2.jpg, 3.jpg, 4.jpg etc in the db and then
I can just drop in the pictures since the path would be the same.
I'm using php/mysql for the db end.
Many thanks in advance!
dwnoobWhy not have a record ID# and have the code programatically
generate the
image name? That way you wouldn't need an image field at all,
e.g.,
<img src="/path/path/path/imagename -<?php echo
$rs_recordset['recordID'];
?>.jpg"....
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"dwnoob" <[email protected]> wrote in
message
news:ftrh3v$2a8$[email protected]..
> Hello, I would like to create paginated recordsets
without specifying the
> filename over and over again. For example, if I have
folders of pictures
> with
> sequential filenames, is there anyway to get around
manually entering them
> in
> the database? If not, what is the best way to go about
doing this because
> I
> will have a great number of these "books" to create.
Maybe there is a way
> to
> just auto-enumerate a 1.jpg, 2.jpg, 3.jpg, 4.jpg etc in
the db and then I
> can
> just drop in the pictures since the path would be the
same.
>
> I'm using php/mysql for the db end.
>
> Many thanks in advance!
>
> dwnoob
>
>
Maybe you are looking for
-
Fields in PDF form are blank: Another Preview question...
So I get that filling out a form in Preview can create a problem where the end user cannot see the info in those fields unless they click on them. But I have some additional questions: 1. Is just viewing a PDF in Preview without making any changes e
-
Convert a dynamic vhd to fixed vhd using Convert-VHD cmdlet
Hi folks, I have dynamically expanding vhd. Now I want to convert it to fixed size vhd. I used the Convert-VHD cmdlet, which works fine. But if I give the source and want to overwrite my dynamic vhd to the fixed vhd, it is throwing error, such the
-
Formating the output using SO_NEW_DOCUMENT_SEND_API1
Hi , I am using the FM 'SO_NEW_DOCUMENT_SEND_API1' for sending data in an internal table as an email . I am wondering whether it will be possible to to send it in the table format with the field names intact. Currently i am able to send the mail but
-
Hi All, I am looking to attach this code to a flash button on click <form method="POST"> <P><Input type="submit" value="table lamp on" name="run_event"></P> </form> the code above sends a command to run an event to my home automation server thanks in
-
Lumia 620: Reset error, Stuck on gears screen
Yeah. I tried to do the Amber update on my phone, but it restarted during the update and it said I didn't have enough space for the update because it wanted to redownload the files rather than use the ones already there. I couldn't clear any more spa