سؤال

i have 3 tables audios,videos,images

they all have dateadded and uid

i want to select all (select *) from these tables where uid=1 and order all the results by dateadded, very confused what the query would be like?

هل كانت مفيدة؟

المحلول

if tha tables hold the same information you can use union, e.g.:

select name, date_added
from(
  select video_name as name,date_added, uid
  from videos
  union all
  select audio_name as name,date_added, uid
  from audios
  union all
  select image_name as name,date_added, uid
  from images
) u
where uid = 1
order by date_added

نصائح أخرى

If the 3 table has 1 same field like groupID or something like that you can use left join or inner join depending on what output would you want to have.

using left join:

select * from videos v left join audios a on v.groupID = a.groupID
left join images i on v.groupID = i.groupID

note: just change the word "left" to "inner" if you want to use the other type of join. It doesn't have to have the same field name "groupID". But it is necessary to have a common functionality or it represents something which is related to each other.

Links: here are some links that may help you http://www.w3schools.com/sql/sql_join.asp http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

enjoy coding..:)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top