php - Finding tablename -


i've 8 tables.. assume x1,x2...x8. these tables have similar structure fields as: id,content,pageview.

pageview count number of views of particular id. post's stored in rows particular id's.

i want find first top 10 post on basis of pageview these 8 tables.

i used :

$sql="select id,content x1,x2,x3,x4,x5,x6,x7,x8 order pageview;" 

results comes up.ok! suppose results like

id content
13 1 19 okay .. .. .

in result want find id:19 belongs table? can run loops match content wont fast enough , logic..

any solution find tablename of particular id?

your sample query not run if have same field names in each table. not mention you're producing cartesian product since you're not joining on of fields.

i think might looking union instead:

select * (    select 'x1' whichtable, id, content, pageview x1    union    select 'x2' whichtable, id, content, pageview x2    ...    union    select 'x8' whichtable, id, content, pageview x8 ) t order pageview 

then can use whichtable field see table result came from.

here sample sql fiddle demo.


just reread post, , if you're looking table contains id 19, can add clause above query:

select * (    select 'x1' whichtable, id, content, pageview x1    union    select 'x2' whichtable, id, content, pageview x2    ...    union    select 'x8' whichtable, id, content, pageview x8 ) t id = 19 order pageview 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -